Created
May 15, 2021 22:03
-
-
Save vrat28/905b68d4c53fc7c5a8b130ec50b7a796 to your computer and use it in GitHub Desktop.
Valid Number (Python)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def isNumber(self, S: str) -> bool: | |
num, exp, sign, dec = False, False, False, False | |
for c in S: | |
if c >= '0' and c <= '9': num = True | |
elif c == 'e' or c == 'E': | |
if exp or not num: return False | |
else: exp, num, sign, dec = True, False, False, False | |
elif c == '+' or c == '-': | |
if sign or num or dec: return False | |
else: sign = True | |
elif c == '.': | |
if dec or exp: return False | |
else: dec = True | |
else: return False | |
return num |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment