My python code face integer overflow problem


  • 0
    M

    Here is the solution I came up with, but it always fail the test case when using amount '1534236469' which seems still within 32 bits, could anyone please give any suggestions.

    class Solution(object):
        def reverse(self, x):
            if x.bit_length() < 32:
                if x >= 0:
                    return int(str(x)[::-1])
                else:
                    x *= -1
                    reverse_temp = str(x)[::-1]
                    return int('-' + reverse_temp)
            else:
                return 0
    

Log in to reply
 

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