Leetcode Problem 520. Detect Capital

520. Detect Capital

Leetcode Solutions

Character by Character Approach

  1. Initialize three boolean variables to true, representing the three cases.
  2. Iterate over each character in the word.
  3. For case 1, check if all characters are uppercase. If a lowercase is found, set the corresponding boolean to false.
  4. For case 2, check if all characters are lowercase. If an uppercase is found, set the corresponding boolean to false.
  5. For case 3, check if only the first character is uppercase and the rest are lowercase. If this is not the case, set the corresponding boolean to false.
  6. If any of the three booleans is true, return true. Otherwise, return false.
UML Thumbnail

Regex Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...