Reverse digits of an integer.
Example1:?x = 123, return 321
Example2:?x = -123, return -321
?
public class Solution { public int reverse(int x) { int num = 0; for (; x != 0; x/=10) { if (Math.abs(num) > Integer.MAX_VALUE/10) { return 0; } num = num*10 + x%10; } return num; } }
?
?
?
原文:http://hcx2013.iteye.com/blog/2212632