import re import math class Solution(object): def myAtoi(self, str): """ :type str: str :rtype: int """ r1 = re.match(r‘\s*[\-\+]?\d+‘,str) if r1!=None : r2=int(r1.group()) if r2<=-2147483648: return -2147483648 elif r2>=2147483648: return 2147483647 else: return r2 else: return 0
原文:https://www.cnblogs.com/xiao-xue-di/p/10291872.html