Weird expected output error. OJ said reverse of 1534236469 is 0?


  • 0
    P

    Hey Guys, so I wrote my program as below:

    def reverse(self, x):
    
        sign = 1
        if x < 0:
            sign *=-1
            
        x = list(str(abs(x)))
        x = x[::-1]
        x = int(''.join(x))*sign
        return x
    

    However for some reason, test case below just wouldn't pass.
    Input:
    1534236469
    Output:
    9646324351
    Expected:
    0

    I think it has to do with overflow but in python sys.maxint is 9223372036854775807, (in other words, way beyond this test case). I couldn't figured out why its expected output as 0. Please help, thank you!


  • 0
    T

    Ran into this issue as well, looks like it's bugged for other values also.


  • 4
    P

    @thedrizzle43 Hey I figured out last time.
    So for an int type, its range is limited from -2^31 to 2^31-1;
    so in this case because 9646324351 > 2^31-1, leetcode wants us to output 0.


  • 0
    A

    2147483647 is the biggest number,and 9646324351 is bigger than 2147483647,so it overflows and the output should be 0.


Log in to reply
 

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