Palindrome Number

Desicription

Determine whether an integer is a palindrome. Do this without extra space.

Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public:
bool isPalindrome(int x) {
stringstream stream;
string res;
stream << x;
stream >> res;
for(int i = 0, j = res.size()-1; i <= j; i++, j--){
if(res[i] != res[j])
return 0;
}
return 1;
}
};