文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
- Version 1
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0) {
return false;
}
int m = x;
int y = 0;
while(m) {
y = y * 10 + m % 10;
m /= 10;
}
return x == y;
}
};
- Version 2
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0 || (x != 0 && x % 10 == 0)) {
return false;
}
int m = x;
int y = 0;
while(m) {
y = y * 10 + m % 10;
m /= 10;
}
return x == y;
}
};