题目:实现一个atoi函数,使其能将字符转换成整数
def myAtoi(self,str:str)
str=str.strip()
length=len(str)
result=' '
i=0
if str=='-' orstr=='+'ofstr==' ':
retrun 0
elif i<length and str[i].isdigit():
while i<length and str[i].isdigit():
reslut+=str[i]
i+=1
if i==length:
break
if int(result)<=-2**31:
return(-2**31-1)
elif int(result)>=2**31-1:
return(2**31-1)
else:
return(int(result))
elif i<length and (str[i]=='-' or str[i]=='+'):
reult+=str[i]
i+=1
if i<length and str[i].isdigit():
while i<length and ste[i].isdigit() :
result+=str[i]
i+=1
if i==length:
break
if int(result)<=-2**31:
return(-2**31)
elif int(result)>=2**31-1:
return(2**31-1)
else:
return (int(result))
else:
return 0
else:
return 0