What is the python regluar expression solution to the valid number question?


  • 1
    C
    class Solution:
        # @param {string} s
        # @return {boolean}
        def isNumber(self, s):
            if re.match('\s*[\+-]?(\d+\.?|\.\d+)\d*(e[\+-]?\d+)?\s*',s):
                return True
            else:
                return False
    

    It fails in the case: s='0e'
    Can anybody help on this?


  • 0
    D

    add '^' and '$' at beginning and end of the pattern


Log in to reply
 

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