#520

Detect Capital

pupil · 410 · lc easy +25 · verified · 56.5% accepted · 3,580 likes · top 51%

play →

Description

Capitalization in a word is considered correct if exactly one of these three patterns holds:

- Every letter is uppercase, e.g. "USA".

- Every letter is lowercase, e.g. "leetcode".

- Only the very first letter is uppercase, e.g. "Google".

Given a string word, return true if its capitalization is correct, and false otherwise.

Example 1:

Input: word = "USA"
Output: true

Example 2:

Input: word = "FlaG"
Output: false

Code

1
2
3