Back to problems Sign in to unlock
Leetcode
Easy
Strings
Detect Capital
Determine whether the capitalization pattern of a word is valid.
Acceptance 50%
Problem Statement
Problem
Given a word, determine whether it uses capital letters correctly.
A word is considered to have correct capitalization if one of the following is true:
- All letters are uppercase.
- All letters are lowercase.
- Only the first letter is uppercase and all remaining letters are lowercase.
Return true if the word is correctly capitalized, otherwise return false.
Notes
- Treat the input as a single word with alphabetic characters only.
- The answer depends only on the letter casing pattern.
Input Format
- A single string
wordconsisting of English letters.
Output Format
- Return
trueif the capitalization is valid, otherwise returnfalse.
Constraints
1 <= word.lengthwordcontains only alphabetic English letters.
Examples
Sample cases returned by the problem API.
Example 1
Input
word = "USA"
Output
true
Explanation
All letters are uppercase.
Example 2
Input
word = "leetcode"
Output
true
Explanation
All letters are lowercase.
Show 2 more examples
Example 3
Input
word = "Google"
Output
true
Explanation
Only the first letter is uppercase.
Example 4
Input
word = "FlaG"
Output
false
Explanation
The capitalization does not match any allowed pattern.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.