class Solution {
public:
bool isPalindrome(string s)
{
if(s.size()==0)
return true;
const int len=s.size();
int start=0;
int end=len-1;
while(start<end)
{
while(!isValidStr(s[start]) && start<end)
++start;
while(!isValidStr(s[end]) && start<end)
--end;
if(start<end && tolower(s[start])!=tolower(s[end]) )
return false;
++start;
--end;
}
return true;
}
bool isValidStr(char s)
{
if(s>='a' && s<='z' || s>='A'&& s<='Z' || s>='0' && s<='9')
return true;
else
return false;
}
};
Valid Palindrome
最新推荐文章于 2024-01-04 12:53:14 发布