Example1: x = 123, return 321
Example2: x = -123, return -321
class Solution {
public:
int reverse(int x) {
string s=to_string(x);
for(int i=0,j=s.size()-1;i<j;++i,--j){
swap(s[i],s[j]);
}
if(x<0)
return -atoi(s.c_str());
else
return atoi(s.c_str());
}
};