8. string conversion integer (atoi) (leetcode)

reward:
  1. Review the regular expression, re.findall () returns the qualifying list
  2. When comparing the size of global variables, or with a boundary value relates to the need to use flexible min max
  3. Learn to * usage * can only be used in mass participation in
 
 
 
 
class Solution:
    def myAtoi(self, str: str) -> int:
        return min(max(int(*re.findall('^[+-]?\d+',str.lstrip())),-2**31),2**31-1)

Guess you like

Origin www.cnblogs.com/ChevisZhang/p/12243538.html