# Python Reverse Integer expected Answer is wrong.

• Input:
1534236469
Output:
9646324351
Expected:
0

I submit my code,but it give a tip like that.

• I have same problem.

• I think this problem cause by it defines a max number 2**31-1

• click to show spoilers:

Did you notice that the reversed integer might overflow? Assume the input is a 32-bit integer, then the reverse of 1000000003 overflows. How should you handle such cases?

For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

• I realize this problem after I submit this question. but I still think this answer is wrong cause python support long number not only 32-bit int.

• I had the same problem at first. If the result is bigger than INT_MAX, Python will convert it to long automatically.

• yeah, I also meet this problem. In Python Long int is supported! sad!

• @cha122977 yeah ,I got the same wrong answer. but how to solve?

• I had the same problem at first. If the result is bigger than INT_MAX, Python will convert it to long automatically.

how to solve

• @Bruce_coder I just compare the return number with 0x7fffffff, if it is greater, then return 0.

• @Bruce_coder Cause python int don't have overflow ,

to bypass this
check the result

if abs(result) > 2** 31: return 0

• @jianggau yeah，thanks

• @kimixuchen yeah ,thanks

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