Skip to content

Commit c8e4752

Browse files
authored
Create Solution.py
1 parent 5cb92a1 commit c8e4752

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution:
2+
def myAtoi(self, s):
3+
"""
4+
:type s: str
5+
:rtype: int
6+
"""
7+
8+
s = list(s.split()[0])
9+
Digits = {'0':0, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9}
10+
11+
if s[0] in "+-":
12+
Sign = 1 if s[0] == '+' else -1
13+
s.pop(0)
14+
elif s[0] in Digits:
15+
Sign = 1
16+
else:
17+
return 0
18+
19+
Num = 0
20+
for i in s:
21+
Num *= 10
22+
Num += Digits[i]
23+
24+
return Sign*Num

0 commit comments

Comments
 (0)