标签:style blog color io strong div sp log on
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
1 public class Solution { 2 public int reverse(int x) { 3 int temp=x; 4 int sum=0; 5 if (x<0) { 6 x=-x; 7 } 8 if (x==0) { 9 return 0; 10 } 11 while(x%10==0){ 12 x=x/10; 13 } 14 while (x!= 0) { 15 sum=sum*10+x%10; 16 x=x/10; 17 } 18 if (temp>0) { 19 return sum; 20 } 21 return 0-sum; 22 } 23 }
标签:style blog color io strong div sp log on
原文地址:http://www.cnblogs.com/birdhack/p/3967102.html