We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e8b9f5c commit 5bc741fCopy full SHA for 5bc741f
1 file changed
LeetCode/myAtoi.py
@@ -0,0 +1,34 @@
1
+class Solution:
2
+ def myAtoi(self, str):
3
+ num = ["{}".format(i) for i in range(10)]
4
+ nums = num + ['-', '+']
5
+ l = len(str)
6
+ for i in range(len(str)):
7
+ if str[i] == ' ':
8
+ continue
9
+ elif str[i] in nums:
10
+ l = i
11
+ break
12
+ else:
13
+ return 0
14
+ r = len(str)
15
+ for i in range(l + 1, len(str)):
16
+
17
+ if str[i] in num:
18
+ # print(str[i])
19
20
21
+ # print(i)
22
+ r = i
23
24
+ # print(str[l:r])
25
+ if str[l:r] in ['', '-', '+']:
26
27
+ n = int(str[l:r])
28
+ L = pow(-2, 31)
29
+ R = pow(2, 31) - 1
30
+ if n < L:
31
+ return L
32
+ if n > R:
33
+ return R
34
+ return n
0 commit comments