python try...except...haha


  • 0
    class Solution(object):
        def isNumber(self, s):
            if len(s) == 0:
                return False
            if '+ ' in s:
                return False
            if '- ' in s:
                return False
            try:
                if int(s) or 1:
                    return True
            except:
                try:
                    if float(s) or 1:
                        return True
                except:
                    return False
    

Log in to reply
 

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