Detect Capital - Problem
We define the usage of capitals in a word to be right when one of the following cases holds:
- All letters in this word are capitals, like
"USA" - All letters in this word are not capitals, like
"leetcode" - Only the first letter in this word is capital, like
"Google"
Given a string word, return true if the usage of capitals in it is right.
Input & Output
Example 1 — Proper Case
$
Input:
word = "Google"
›
Output:
true
💡 Note:
First letter 'G' is uppercase, remaining letters 'o', 'o', 'g', 'l', 'e' are lowercase. This matches the third valid pattern.
Example 2 — All Uppercase
$
Input:
word = "USA"
›
Output:
true
💡 Note:
All letters 'U', 'S', 'A' are uppercase. This matches the first valid pattern.
Example 3 — Invalid Mixed Case
$
Input:
word = "FlaG"
›
Output:
false
💡 Note:
Mixed case with 'F' and 'G' uppercase, 'l' and 'a' lowercase. This doesn't match any of the three valid patterns.
Constraints
- 1 ≤ word.length ≤ 100
- word consists of lowercase and uppercase English letters
Visualization
Tap to expand
Understanding the Visualization
1
Input Word
Check capitalization pattern of input string
2
Pattern Match
Verify against three valid patterns
3
Result
Return true if matches any valid pattern
Key Takeaway
🎯 Key Insight: Only three patterns are valid - count uppercase letters to efficiently determine which pattern matches
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code