1. 程式人生 > >leetcode 520. 檢測大寫字母 (Detect Capitcal) python3 最簡程式碼(利用str內建函式,並且將條件放入返回值中)

leetcode 520. 檢測大寫字母 (Detect Capitcal) python3 最簡程式碼(利用str內建函式,並且將條件放入返回值中)

class Solution:
    def detectCapitalUse(self, word):
        """
        :type word: str
        :rtype: bool
        """

        # 思路一 
        # if word.lower() == word or word.capitalize() == word or word == word.upper():
            # return True
        # return False

        # 思路二:直接在return 中判斷,進一步簡化語句                     注意特殊條件''
return word.islower() or word.isupper() or word.istitle() or word == ''