-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8.py
32 lines (27 loc) · 774 Bytes
/
8.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
# coding = utf8
class Solution(object):
def myAtoi(self, str):
MAXNUM = 2147483647
MINNUM = -2147483648
r = ""
for k, v in enumerate(str):
if v == " " and r == "":
continue
if v == "-" and r == "":
r += v
continue
if v == "+" and r == "":
r += v
continue
if v in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]:
r += v
else:
break
r = 0 if r in ['', '-', '+'] else int(r)
if r > MAXNUM:
r = MAXNUM
if r < MINNUM:
r = MINNUM
return r
if __name__ == "__main__":
print Solution().myAtoi("-12321adas")