Leedcode-检测大写字母

自己写的:

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

 

posted @ 2024-05-31 12:58  Junior_bond  阅读(6)  评论(0)    收藏  举报