161ms lazy python solution


  • -6
    B

    I don't know whether it's valid using exception. But if it's available, then nothing is easier than that.

    class Solution:
        # @param s, a string
        # @return a boolean
        def isNumber(self, s):
            try:
                x = float(s)
            except:
                return False
            
            return True

Log in to reply
 

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