Question:
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
Example3: x = 120, return 21
Note:Assume we are dealing with an environment which could only hold integers within the 32-bit signed integer range. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
My answer in Java:
|
|
Better answer in Java:
|
|
Didn’t thought about over integer overflows, why this problem will happen, we know that the range of integer is -2147483648~2147483647. So if we want to traverse the integer 1000000009, the traversed number 9000000001 will be out of range, so we need to judge the overflow situation.
Answer in python:
|
|
But I have a consider is that why the code which are annotated can’t not run when the input integer is -321