看家本领不能丢,准备2021年每天一道leetcode题目,尽量不间隔,Python3.8
import re
def myAtoi(s: str) -> int:
return max(min(int(*re.findall('^[\+\-]?\d+', s.lstrip())), 2 ** 31 - 1), -2 ** 31)
s = "4193 with words"
print(myAtoi(s))
思路,首先是数值范围问题,这里我们可以用min和max函数来搞定,然后匹配的话,就是直接用正则表达式,很方便的,改天不使用库函数实现一下。

博主打算在2021年每天做一道LeetCode题目且尽量不间隔,使用Python 3.8。解题思路上,数值范围问题用min和max函数解决,匹配则使用正则表达式,后续还计划不使用库函数实现。
1436





