class Solution(object):
def myAtoi(self, str):
"""
:type str: str
:rtype: int
"""
s = str.strip()
if len(s) == 0:
return 0
flag = 1
if s[0] in ["+", "-"]:
if s[0] == "-":
flag = -1
s = s[1:]
ans = 0
for c in s:
if c >= "0" and c <= "9":
ans = ans * 10 + ord(c) - ord("0")
else:
break
ans *= flag
if ans < -2 ** 31:
return -2 ** 31
if ans > 2 ** 31 - 1:
return 2 ** 31 - 1
return ans