解题思路
此题只要保证条件成立即可
- 全都是大写
- 有大写有小写时,第一个是大写其余均为小写
- 全是小写
以上结果满足返回True
代码
class Solution(object): def detectCapitalUse(self, word): """ :type word: str :rtype: bool """ num_A,num_a = 0,0 for i in word: if 65 <= ord(i) <= 90: num_A += 1 else: num_a += 1 if num_A == 1 and 65 <= ord(word[0]) <= 90: return True if num_A == len(word) or num_a == len(word): return True else: return False