import re classSolution(object): defmyAtoi(self, str): """ :type str: str :rtype: int """ str = str.strip() match = re.findall('^([+-]?\d+).*$', str) if match == []: num = 0 else: num = int(match[0]) if num >= 2 ** 31: num = (2 ** 31) - 1 elif num <- 2 ** 31: num =- 2 ** 31 return num