标签:
注意Integer.MIN_VALUE的绝对值是比Integer.MAX_VALUE大1的
public class Solution { public int reverse(int x) { int res = 0; int num = Math.abs(x); while (num != 0) { if (res > (Integer.MAX_VALUE - num%10 )/10) { return 0; } res = res*10 + num % 10; num = num/10; } if (x < 0) { return -res; } else { return res; } } }
标签:
原文地址:http://www.cnblogs.com/77rousongpai/p/4499250.html