using try and except python solution


  • 0
    D
            l = s.split()
            if len(l) > 1:
                return False
            try:
                int(s)
                return True
            except ValueError:
                try:
                    float(s)
                    return True
                except ValueError:
                    return False
    

    This is a simple concise solution using try and except. i split the string at first b/c you need to check for blank spaces because int() or float() return True on instances like so '+ ' when in this problem they should return False


Log in to reply
 

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