LeetCode--Python解析【Detect Capital】(520)
程序员文章站
2022-03-09 22:38:09
...
题目:
方法:
class Solution:
def detectCapitalUse(self, word):
"""
:type word: str
:rtype: bool
"""
test = word.upper()
test1 = word.lower()
if test == word or test1 == word:
return True
for i in range(1,len(word)):
if word[i] == test[i]:return False
return True
首先转换为全部大写和全部小写,如果相等的话返回True
然后从第二个字符开始,与转换为全部大写的字符串开始比价
如过有相等的元素出现则返回False
推荐阅读
-
LeetCode - 520 - 检测大写字母(detect-capital)
-
Java/520. Detect Capital 检测大写字母
-
[高级编程技术作业]LeetCode Problem 520. Detect Capital
-
Leetcode 520. Detect Capital (python+cpp)
-
Leetcode PHP题解--D81 520. Detect Capital
-
Leetcode PHP题解--D81 520. Detect Capital
-
520. Detect Capital
-
String:520. Detect Capital
-
LeetCode--Python解析【Detect Capital】(520)
-
【String-easy】520. Detect Capital 检查是否是Capital