Simple python code! [Accepted]! { Without using any additional helper variables!! }


  • 1
    V
    class Solution:
        # @param s, a string
        # @return a boolean
        def isNumber(self, s):
            try:
                float(s)                 # If error is shown then print False else True
                return True                
            except:
                return False

  • 0
    E

    A python developer that doesn't immediately do this is actually a java developer in disguise. Especially since (A) no detailed specification is provided and (B) there was not an explicit ban on try-except statements.


  • 0
    C

    I disagree, the obvious purpose is to come up with actual implementation.


Log in to reply
 

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