Doubt in the reverse integer problem


  • 0
    R

    I used python for solving. This is my implementation -

    class Solution(object):
        def reverse(self, x):
            if x>0:
                return int(''.join(list(reversed(str(x)))))
            elif x<0:
                return int('-'+''.join(list(reversed(str(x*(-1))))))
            else:
                return 0
    

    When I run this on leetcode I get wrong answer for the following test case -
    Input:
    1534236469
    Output:
    9646324351
    Expected:
    0

    But when I run it using Pycharm on my local machine, it gives me the output which I am getting when run on leetcode i.e. 9646324351. So shouldn't that be the expected answer?
    I understand the problem asks me to return 0 if overflow occurs, but in case of python, overflow does not occur - the variable automatically resizes itself. But still 0 is the expected answer. Why?

    Please help.


Log in to reply
 

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