Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
class Solution { public: int reverse(int x) { int Answer=0; if(-10 < x && x < 10) return x; bool z = true; if(x < 0) {z = false; x = -x;} while(x!=0) { Answer=Answer*10+x%10; x=x/10; } if(z==false) Answer=-Answer; return Answer; } };
原文地址:http://blog.csdn.net/u013018721/article/details/41018503