https://leetcode.com/problems/reverse-integer/#/description 注意溢出的情况
Reverse digits of an integer.
Example1: x = 123, return 321 Example2: x = -123, return -321
Note: The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.
public class Solution {
public int reverse(
int x) {
int a;
long temp=
0;
while(x!=
0)
{
a=x%
10;
temp=temp*
10+a;
x/=
10;
}
return (temp>Integer.MAX_VALUE || temp<Integer.MIN_VALUE )?
0:(
int)temp;
}
}