題意
Determine whether an integer is a palindrome. Do this without extra space.
click to show spoilers.
Subscribe to see which companies asked this question.
解法
實現
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0) return false;
long long y = x, r = x;
long long p = y;
long long z = 0;
while(y != 0){
int r = y % 10;
z = z * 10 + r;
y = y / 10;
}
return z == p;
}
};