- first attempt
class Solution {
public:
bool isPalindrome(int x) {
//reverse number is the same
if(x<0)
return false;
if(x == 0)
return true;
int same = x;
int result = 0 ;
int bit;
while(same!=0)
{
bit = same%10;
result = result*10+bit;
same/=10;
}
return (result==x);
}
};
网友评论