leetcode String to Integer (atoi) python

class Solution(object):
def myAtoi(self, str):
"""
:type str: str
:rtype: int
"""
intMax=2147483647
intMin=-2147483648
str=str.strip()
strLen = len(str)
if strLen <= 0:
return 0 bolNegative = False
tmp = str[0]
start=0 if tmp == '-' or tmp == '+':
start=1 if tmp == '-':
bolNegative = True
rs=0
for i in range(start, strLen ):
tmp = str[i]
if tmp >= '' and tmp <= '':
rs=rs*10+int(tmp)
elif tmp == '-' or tmp == '+':
return 0
else:
break
intTmp = rs
if bolNegative:
intTmp*=-1
if intTmp > intMax:
return intMax
if intTmp < intMin:
return intMin
return intTmp
上一篇:安卓自动化测试工具MonkeyRunner之使用ID进行参数化,以及List选择某项和弹出框点击确定的写法


下一篇:Redis 事物