class Solution
{
public:
bool isPalindrome(int x)
{
if(x<0) return false;
if(x==0) return true;
if(x>0)
{
if(x<10) return true;
if(x % 10 == 0) return false;
else
{
std::vector<int> v;
int a=x;
while(a>0)
{
int digit = a % 10;
v.push_back(digit);
a = a / 10;
}
int len = v.size();
for(int i = 0; i < ceil(len / 2); i++)
{
if(v.at(i) !=v.at(len-1-i) ) return false;
}
}
}
return true;
}
};
Leetcode 09 | Palindrome Number
最新推荐文章于 2024-08-15 05:02:54 发布