use regular expression


  • 0
    Q
    ## QM
    class Solution(object):
        def detectCapitalUse(self, word):
            """
            :type word: str
            :rtype: bool
            """
            import re
            pat = '([A-Z]*|[A-Z][a-z]*|[a-z]*)$'
            return True if re.compile(pat).match(word) else False
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.