-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatoi.py
More file actions
26 lines (25 loc) · 717 Bytes
/
atoi.py
File metadata and controls
26 lines (25 loc) · 717 Bytes
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
class sol(object):
def atoi(self, string):
'''
Need to consider all the possible inputs of strings
'''
i = 0
temp = ''
for i, item in enumerate(string):
if (item == '-' or item == '+') and temp == '':
temp += item
elif item == ' ' and temp == '':
continue
elif item >= '0' and item <= '9':
temp += item
else:
break
sign = ['-', '+']
if temp == '' or temp in sign:
return 0
elif temp[0] == '+':
return int(temp[1:])
return min(int(temp))
mysol = sol()
string = ' - 12'
print mysol.atoi(string)