class Solution:
def myAtoi(self,str:str)->int:
numdic={"0":0,"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9}
i=0
while i<len(str) and str[i]==" ":
i+=1
if i>len(str) or (str[i] not in numdic and str[i] not in ("+","-")):
return 0
sign=1
if str[i]=="-":
sign=-1
i+=1
elif str[i]=="+":
i+=1
num=0
boundry=(1<<31)-1 if sign>0 else 1<<31
while i< len(str) and str[i] in numdic:
num=num*10+numdic[str[i]]
i+=1
if num>boundry:
return sign*boundry
return sign*num
2020/2/10leetcode06
猜你喜欢
转载自blog.csdn.net/dongxieaitonglao/article/details/104267557
今日推荐
周排行