Last active
August 29, 2015 14:03
-
-
Save walkingtospace/0dd5cc4b5fca7546e847 to your computer and use it in GitHub Desktop.
reverse-integer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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