自己寫的:
class Solution: def detectCapitalUse(self, word: str) -> bool: n=len(word) count=0 for i in word: if self.is_upper(i): count+=1 if count==0: return True elif count==n: return True elif self.is_upper(word[0]) and count==1: return True else: return False def is_upper(self,char): if not (ord('A')<=ord(char)<=ord('Z')): return False else: return True