[LeetCode]#520. Detect Capital

Environment: Python 3.7

Key technique: .isupper, islower, slice

Example 1:

Input: "USA"
Output: True

Example 2:

Input: "FlaG"
Output: False


There are three rules in this problem.

  1. All letters in this word are capitals, like “USA”.
  2. All letters in this word are not capitals, like “leetcode”.
  3. Only the first letter in this word is capital, like “Google


class Solution:
def detectCapitalUse(self, word: str) -> bool:
if word.isupper()==True:
return True
elif word.islower()==True:
return True
elif word[0].isupper() and word[1:].islower() ==True:
return True
return False

Submitted result:

Interesting in any computer science.