Five lines of Python


  • 0
    C

    It's great that we can fall back on the built-in python way of converting things to numbers:

    class Solution(object):
        def isNumber(self, s):
            """
            :type s: str
            :rtype: bool
            """
            try:
                float(s)
            except ValueError:
                return False
            
            return True
    

Log in to reply
 

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