The expected value is not reverse of the number and thus it does not accept my solution.


  • 0
    S

    My python code:

        if x<0:
            neg = True
        else:
            neg=False
        
        num = abs(x)
        lst = []
        while(num>0):
            r = num%10
            num = num//10
            lst.append(r)
        mul = 1
        sum = 0
        for i in range(len(lst)-1,-1,-1):
            sum+=lst[i]*mul
            mul = mul*10
        
        if neg == False:
            return sum
        else:
            return (0-sum)
    

    it doesnot pass a test case where the program says the output for 1534236469 should be 0. I dont get it.


  • 2
    C

    I think if the final answer is greater than Integer.MAX_VALUE or smaller than Integer.MIN_VALUE, you should return 0


  • 0

    It even says so explicitly (albeit in the spoilers section). Only... there is no overflow in Python, so no wonder the OP got confused.


Log in to reply
 

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