-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidNumber.py
More file actions
36 lines (33 loc) · 925 Bytes
/
Copy pathValidNumber.py
File metadata and controls
36 lines (33 loc) · 925 Bytes
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
class Solution:
def isNumber(self, s):
"""
:type s: str
:rtype: bool
"""
i, n = 0, len(s)
while i < n and s[i].isspace():
i += 1
if i < n and s[i] == '+' or s[i] == '-':
i += 1
isNumber = False
while i < n and s[i].isnumeric():
isNumber = True
i += 1
if i < n and s[i] == '.':
i += 1
while i < n and s[i].isnumeric():
i += 1
isNumber = True
if i < n and s[i] == 'e':
i += 1
isNumber = False
if i < n and (s[i] == '+' or s[i] == '-'):
i += 1
while i < n and s[i].isnumeric():
i += 1
isNumber = True
while i < n and s[i].isspace():
i += 1
return isNumber and i == n
s = Solution()
print(s.isNumber('e'))