Skip to content

Latest commit

 

History

History
19 lines (18 loc) · 458 Bytes

8.md

File metadata and controls

19 lines (18 loc) · 458 Bytes
class Solution(object):
    def myAtoi(self, str):
        """
        :type str: str
        :rtype: int
        """
        str = str.strip()
        try:
            res = re.search('(^[\+\-]?\d+)', str).group()
            res = int(res)
            res = res if res <= 2147483647 else 2147483647
            res = res if res >= -2147483648 else -2147483648
        except:
            res = 0
        return res

字符串 细节 正则表达式