dsa · easy
Detect Capital
A word uses capitals correctly in exactly three situations:
- every letter is uppercase (
OK,USA) - every letter is lowercase (
ok,hello) - only the first letter is uppercase and the rest are lowercase (
Ok,Hello)
Any other mix (hEllo, FlaG, oK) is incorrect. Return whether word is one of the three correct shapes.
Example
word = "OK": both letters uppercase → true.
word = "Hello": first uppercase, the rest lowercase → true.
word = "hEllo": an uppercase letter sits in the middle after a lowercase start → false.
word = "g" is a single lowercase letter, which is the all-lowercase shape → true.
## Arguments - word — string of English letters to check for capital use
Constraints
1 <= word.length <= 100 word consists of lowercase and uppercase English letters Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: "OK" Expected: true
Example 2
Input: "Hello" Expected: true
Example 3
Input: "hEllo" Expected: false