We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 5034b9d + 307be30 commit ff4fc2bCopy full SHA for ff4fc2b
008_String_to_Integer_(atoi).py
@@ -0,0 +1,30 @@
1
+class Solution:
2
+ def myAtoi(self, s: str) -> int:
3
+ strs=s.lstrip(' _')
4
+ result = []
5
+ minus=False
6
+ ch=True
7
+ if len(strs)>=2:
8
+ if (strs[0]=='-' or strs[0]=='+') and (strs[1]=='-' or strs[1]=='+'):
9
+ return 0
10
+ if len(strs)==0:
11
12
+ if strs[0]=='+':
13
+ strs=strs[1:]
14
+ pass
15
+ elif strs[0]=='-':
16
+ minus =True
17
18
+ for i in range(len(strs)):
19
+ if ord(strs[i]) in range(48,58):
20
+ result.append(strs[i])
21
+ ch=False
22
+ else: break
23
+ if ch:
24
25
+
26
+ r=''.join(result)
27
+ sum= int(r) if not minus else -int(r)
28
+ if sum > 2**31-1 or sum < -2**31:
29
+ return 2**31-1 if not minus else -2**31
30
+ else: return sum
0 commit comments