-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalid_string_integer.py
More file actions
49 lines (34 loc) · 1.08 KB
/
Copy pathvalid_string_integer.py
File metadata and controls
49 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Solution:
def isNumber(self, S: str) -> bool:
num, sign, exp, dec = False, False , False, False
for c in S:
if c=='-' or c=='+':
if num or dec or exp:
return False
sign = True
elif c=='.':
if dec or exp:
return False
dec = True
elif c=='e' or c=='E':
if exp or not num:
return False
exp = True
sign = False
num = False
dec = False
elif c>='0' and c<='9':
num = True
else:
return False
return num
solution = Solution()
data = ["2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7", "+6e-1", "53.5e93", "-123.456e789"]
for i in data:
resp = solution.isNumber(i)
print(i, resp)
print('==================')
data = ["abc", "1a", "1e", "e3", "99e2.5", "--6", "-+3", "95a54e53"]
for i in data:
resp = solution.isNumber(i)
print(i, resp)