Input:
1534236469
Output:
9646324351
Expected:
0
I submit my code,but it give a tip like that.
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.
@kimixuchen said in Python Reverse Integer expected Answer is wrong.:
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