python sample code with re


  • 2
    X
    import re
    class Solution(object):
        def myAtoi(self, str):
            r = re.match("[+-]?[0-9]+", str.strip())
            if not r:
                return 0
            y = int(r.group())
            if y < -2147483648:
                y = -2147483648 
            if y > 2147483647:
                y = 2147483647
            return y
    

  • 0
    X
    This post is deleted!

  • 0
    Y

    fantastic, but I do no think you can use "int" type casting directly.


Log in to reply
 

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