字符串转换整数 (atoi)
目录
字符串转换整数 (atoi)
https://leetcode-cn.com/problems/string-to-integer-atoi/
#重点是正则表达式
class Solution:
def myAtoi(s: str):
import re
= re.findall("^[\+\-]?\d+",s.strip())
ss = int(*ss)
res if res > (231-1):
= (231-1)
res if res < -231:
= -231
res return res
WA了四次才整出来,太菜了,以为很简单,没有认真读题,要吸取教训。