class Solution:
def myAtoi(self, str):
s = ''
str = str.lstrip()
for i in range(len(str)):
if str[i].isdigit() or ((str[i] == '+' or str[i] == '-') and i == 0):
s += str[i]
else:
break
if s == '' or s == '+' or s == '-':
return 0
s = int(s)
if s > 2**31 - 1:
return 2**31 - 1
elif s < -2**31:
return -2**31
return s