Python 84ms solution using re


  • 2
    H
    import re
    class Solution(object):
    def isNumber(self, s):
        """
        :type s: str
        :rtype: bool
        """
        if re.match('^\s*(\+|-)?(\d+|\d*\.\d+|\d+\.\d*|\d+\.?\d*e[\+|-]?\d+|\d*\.?\d+e[\+|-]?\d+)\s*$',s):
            return True
        else:
            return False

  • 0
    H
    This post is deleted!

Log in to reply
 

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