re solution in python


  • 0
    N
    def myAtoi(self, str):
            try:
                str = str.lstrip()
                import re
                p = re.compile(r'^([-+]{0,1}[\d]+)[\D]*')
                ma = p.findall(str)
                i = int(ma[0])
                if i > 2147483647:
                    return 2147483647
                elif i < -2147483648:
                    return -2147483648
                return i
            except:
                return 0
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.