Leetcode 520 Detect Capital

Posted 周洋的Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 520 Detect Capital相关的知识,希望对你有一定的参考价值。

送分题.

# 送分题
class Solution(object):
    def detectCapitalUse(self, word):
        """
        :type word: str
        :rtype: bool
        """
        if len(word)==1:
            return True
        
        ans=True
        if self.is_uppercase(word[0]):
            if self.is_uppercase(word[1]):
                for c in word[1:]:
                    if self.is_lowercase(c):
                        return False
            else:
                for c in word[1:]:
                    if self.is_uppercase(c):
                        return False
            return True
        else: # the first letter is lowercase
            for c in word[1:]:
                if self.is_uppercase(c):
                    return False
        return True
    def is_uppercase(self,letter):
        return (letter>=A)&(letter<=Z)
    def is_lowercase(self,letter):
        return (letter>=a)&(letter<=z)

 

以上是关于Leetcode 520 Detect Capital的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 520. Detect Capital

Leetcode 520. Detect Capital

LeetCode - 520. Detect Capital

leetcode-520-Detect Capital

[LeetCode&Python] Problem 520. Detect Capital

Leetcode 520 Detect Capital