Skip to content

Instantly share code, notes, and snippets.

@walkingtospace
Last active August 29, 2015 14:03
Show Gist options
  • Save walkingtospace/0dd5cc4b5fca7546e847 to your computer and use it in GitHub Desktop.
Save walkingtospace/0dd5cc4b5fca7546e847 to your computer and use it in GitHub Desktop.
reverse-integer
https://oj.leetcode.com/problems/reverse-integer/
class Solution {
public:
int reverse(int x) {
if(x < 10 && x > -10) return x;
int result = 0;
stringstream ss;
ss << x;
string res = ss.str();
if(x < 0) {
std::reverse((++res.begin()),res.end());
} else {
std::reverse(res.begin(),res.end());
}
return atoi(res.c_str());
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment