```python
#!/usr/bin/env python
coding=utf-8
def myAtoi(str): ret=0 negative=False maxint=2147483647 str=str.strip() for i in range(len(str)): if i == 0: if str[0] == ‘-‘: negative=True else: if str[0] >= ‘0’ and str[0] <= ‘9’: ret = int(str[i])- int(‘0’) elif str[0] != ‘+’: break else: if str[i] >= ‘0’ and str[i] <=’9’: ret = ret * 10 + int(str[i]) - int(‘0’) if negative == True: if ret > maxint + 1: ret = maxint + 1 break else: if ret > maxint: ret = maxint break else: break
if negative == True:
ret = -ret
return ret
myAtoi(“0.123.00”) myAtoi(“+000123”) myAtoi(“-123”) myAtoi(“-12300”)