Given a word, you need to judge whether the usage of capitals in it is right or not.



We define the usage of capitals in a word to be right when one of the following cases holds:

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 if it has more than one letter, like "Google".

Otherwise, we define that this word doesn't use capitals in a right way.



Example 1:

Input: "USA"
Output: True



Example 2:

Input: "FlaG"
Output: False



Note:
The input will be a non-empty word consisting of uppercase and lowercase latin letters.

Difficulty: introductory

Starter code:

class Solution:
    def detectCapitalUse(self, word: str) -> bool:
        

Solutions:
class Solution:
     def detectCapitalUse(self, word):
         """
         :type word: str
         :rtype: bool
         """
         if len(word) == 0:
             return True
         elif word.isupper() or word.islower():
             return True
         elif len(word) > 1:
             return word.istitle()
         else:
             return False

class Solution:
     def detectCapitalUse(self, word):
         """
         :type word: str
         :rtype: bool
         """
         if word.isupper():
             return True
         if word.islower():
             return True
         if word[0].isupper() and word[1:].islower():
             return True
         
         return False

class Solution:
     def detectCapitalUse(self, word):
         """
         :type word: str
         :rtype: bool
         """
         for i, w in enumerate(word):
             is_cap = ord(w) < ord('a')
             if i == 0:
                 if is_cap:
                     first_cap = True
                     keep_cap = False
                 else:
                     first_cap = False
                     keep_cap = False
             else:
                 if not first_cap and is_cap:
                     return False
                 if keep_cap and not is_cap:
                     return False
                 if not keep_cap and i > 1 and is_cap:
                     return False
                 if i == 1 and is_cap and first_cap:
                     keep_cap = True
         return True
             


class Solution:
     def detectCapitalUse(self, word):
         return word[1:]==word[1:].lower() or word==word.upper()

class Solution:
     def detectCapitalUse(self, word):
         """
         :type word: str
         :rtype: bool
         """
         return word.islower() or word.isupper() or word.istitle()

class Solution:
     def detectCapitalUse(self, word):
         """
         :type word: str
         :rtype: bool
         """
         return word == word.upper() or word == word.lower() or word == word[0].upper() + word[1::].lower()

class Solution:
     def detectCapitalUse(self, word):
         
         return word[1:].islower() or word.isupper() or word.islower()
     
     
     
         """old
         if word[0].isupper():
             if len(word)==1:return True
             if word[1].isupper():
                 for i in range(2,len(word)):
                     if word[i].islower():return False
                 return True                    
             for i in range(2,len(word)):
                 if word[i].isupper():return False
             return True
         for i in range(1,len(word)):
             if word[i].isupper():return False
         return True
         """
         
         """
         :type word: str
         :rtype: bool
         """