标签:value nbsp abs max class int reverse dig ret
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
public class Solution { public int reverse(int x) { if(x==Integer.MIN_VALUE) return 0; long result = 0; int i = 0; int temp = (x>0)?1:0; x = Math.abs(x); while(x != 0){ result *= 10; result += x%10; x /= 10; if(result > Integer.MAX_VALUE || result < Integer.MIN_VALUE) return 0; } return (temp==1)?(int)result:(int)-result; } }
标签:value nbsp abs max class int reverse dig ret
原文地址:http://www.cnblogs.com/iwangzheng/p/6002151.html