Skip to content

Instantly share code, notes, and snippets.

@vrat28
Created May 15, 2021 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrat28/905b68d4c53fc7c5a8b130ec50b7a796 to your computer and use it in GitHub Desktop.
Save vrat28/905b68d4c53fc7c5a8b130ec50b7a796 to your computer and use it in GitHub Desktop.
Valid Number (Python)
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