码迷,mamicode.com
首页 > 其他好文 > 详细

8. 字符串转换整数 (atoi) (leetcode)

时间:2020-01-30 20:47:17      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:比较大小   正则表达式   leetcode   str   字符串转换   tco   传参   atoi   ret   

收获:
  1.复习了正则表达式, re.findall() 返回的是符合条件的list
  2. 当涉及到与全球变量比较大小,或者有边界值的时候需要灵活使用 min max
  3. 学习到了 * 的用法,*只可在传参中使用
 
 
 
 
class Solution:
    def myAtoi(self, str: str) -> int:
        return min(max(int(*re.findall(‘^[+-]?\d+‘,str.lstrip())),-2**31),2**31-1)

8. 字符串转换整数 (atoi) (leetcode)

标签:比较大小   正则表达式   leetcode   str   字符串转换   tco   传参   atoi   ret   

原文地址:https://www.cnblogs.com/ChevisZhang/p/12243538.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!