比较简单
public class Solution {
public static int reverse(int x) {
long flag = 0;
while (x != 0) {
flag = flag * 10 + x % 10;
x = x / 10;
}
while (Math.abs(flag) > 2147483647)
return 0;
return (int) flag;
}
}
注意要考虑数值越界及溢出情况