6 lines Python code using regular expression


  • 0
    class Solution(object):
        def isNumber(self, s):
            import re
            s = s.strip()
            if re.findall('^(\+|-)?((\d*\.?\d+)|(\d+\.?\d*))(e|E)(\+|-)?\d+$',s) or re.findall('^(\+|-)?((\d*\.?\d+)|(\d+\.?\d*))$',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.