-
Notifications
You must be signed in to change notification settings - Fork 481
/
0065.py
34 lines (31 loc) · 890 Bytes
/
0065.py
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
class Solution:
def isNumber(self, s):
"""
:type s: str
:rtype: bool
"""
s = s.lstrip().rstrip()
e, point, num = False, False, False
i, s_len = 0, len(s)
if s_len > 0 and s[i] in '+-':
i += 1
while i < s_len:
c = s[i]
if c in '0123456789':
i += 1
num = True
continue
elif c in 'eE':
if not num or e or i == s_len - 1:
return False
e = True
if s[i+1] in '+-' and i < s_len - 2:
i += 1
elif c == '.':
if point or e:
return False
point = True
else:
return False
i += 1
return num