Python RE Solution


  • 0
    D

    Took me a bit to nail down but here it is:

    class Solution(object):
        def isNumber(self, s):
            if re.match('(^\s*[-+]?0?\d+\s*$)|(^\s*[1-9]+\s*$)|((\d*0+|[1-9]+|\s*)[-+]?\.[0-9]+\s*$)|(^\s*[-+]?\d+\.?\d*?\s*$)|(^\s*\d+$)|(^\s*[-+]?\.?[0-9]+\.?\d*e[-+]?[0-9]+\s*$)', s):
                return True
            else:
                return False
    

Log in to reply
 

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