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 22bd7ae + 748cb24 commit b43d4f2Copy full SHA for b43d4f2
solution/0008.String to Integer(atoi)/Solution.py
@@ -0,0 +1,25 @@
1
+class Solution:
2
+ def myAtoi(self, s):
3
+ """
4
+ :type s: str
5
+ :rtype: int
6
7
+
8
+ try:
9
+ s = list(s.split()[0])
10
+ Sign = {'+':1, '-':-1}[s[0]]
11
+ s.pop(0)
12
+ except IndexError : return 0
13
+ except KeyError: Sign = 1
14
15
+ Num = 0
16
+ for i in s:
17
+ try: Num = int(i) + (Num*10)
18
+ except ValueError: break
19
20
+ Num = Sign*Num
21
+ if Num > 2147483647:
22
+ return 2147483647
23
+ elif Num < -2147483648:
24
+ return -2147483648
25
+ return Num
0 commit comments