- 先全部转为负数处理(因为负数比正数多一个有效位)
- 其他没什么好说的,主要是检测越界问题
public static int reverse(int x) {boolean o = ((x >>> 31) & 1) == 1;int count = 0;int m = Integer.MIN_VALUE / 10;int n = Integer.MIN_VALUE % 10;x = o ? x : -x;while (x != 0) {if (count < m || (count == m && x % 10 < n) ) {return 0;}count = count * 10 + x % 10;x /= 10;}return o ? count : -count;}
