166. Detect Capital Usage

EasyStringString

Given a string word, return 'true' if the usage of capitals in it is correct, 'false' otherwise.

Correct usage means one of:
1. All letters are uppercase (e.g., 'USA').
2. All letters are lowercase (e.g., 'leetcode').
3. Only the first letter is uppercase (e.g., 'Google').

Input: A single string word (only English letters, no spaces).

Output: Return 'true' if capitalization is correct, otherwise 'false'.

Examples

Example 1
Input: USA
Output: true
Explanation: All uppercase → valid.
Example 2
Input: FlaG
Output: false
Explanation: Mixed capitalization → invalid.
Example 3
Input: Google
Output: true
Explanation: First letter upper, rest lower → valid.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →