
可以使用 Python 来实现这个功能,代码如下:
def detectCapitalUse(word: str) -> bool:
return word.isupper() or word.islower() or word.istitle()
# 测试案例
print(detectCapitalUse("USA")) # True
print(detectCapitalUse("leetcode")) # True
print(detectCapitalUse("Google")) # True
print(detectCapitalUse("FlaG")) # False
代码解释:
word.isupper():如果整个单词都是大写,返回True。word.islower():如果整个单词都是小写,返回True。word.istitle():如果只有首字母大写,返回True。
如果满足任意一个条件,就返回 True,否则返回 False。
247

被折叠的 条评论
为什么被折叠?



