Skip to main content
Back to problems
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:

  1. All letters are uppercase.
  2. All letters are lowercase.
  3. 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 word consisting of English letters.

Output Format

  • Return true if the capitalization is valid, otherwise return false.

Constraints

  • 1 <= word.length
  • word contains 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
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.