[LeetCode]#520. Detect Capital
1 min readMar 19, 2020
Environment: Python 3.7
Key technique: .isupper, islower, slice
Example 1:
Input: "USA"
Output: True
Example 2:
Input: "FlaG"
Output: False
Analysis:
There are three rules in this problem.
- All letters in this word are capitals, like “USA”.
- All letters in this word are not capitals, like “leetcode”.
- Only the first letter in this word is capital, like “Google
Solution:
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
else:
return False
Submitted result: