My Python Solution


  • 0
    C
        MAX, MIN = 2147483647, -2147483648
        isNeg = 1 if str(x)[0] == '-' else 0
        res = 0
    
        nlist = [i for i in str(x)]
        nlist.reverse()
        if isNeg:
            nlist.pop()
            nlist.insert(0, '-')
        k = ''
        for n in nlist:
            k += n
        res = int(k)
    
        if res > MAX or res < MIN - 1:
            return 0
    
        return res

Log in to reply
 

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