http://oj.leetcode.com/problems/reverse-integer/
class Solution {
public:
int reverse(int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(x==0) return 0;
vector<int> ans;
bool negative=false;
if(x<0) negative=true;
while(x!=0){
int last=x%10;
ans.push_back(abs(last));
x/=10;
}
int res=0;
for(int i=0;i<ans.size();i++){
res*=10;
res+=ans[i];
}
if(negative) res*=-1;
return res;
}
};