题目:
Reverse digits of an integer. For example: x = 123, return 321
解答:
1 public int reverse(int x) { 2 int ret = 0; 3 4 while(x != 0) { 5 // handle overflow/underflow 6 if(Math.abs(ret) > 214748364) { 7 return 0; 8 } 9 10 ret = ret * 10 + x % 10; 11 x = x / 10; 12 } 13 14 return ret; 15 }