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

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

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

  • 0

    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.