验证回文串
题目描述:
题目来源:力扣
class Solution {
public:
bool IsLetter(char ch)
{
if((ch >='a'&& ch <='z')
||(ch >='A'&&ch <='Z')
||(ch >='0'&&ch <='9'))
return true;
else
return false;
}
bool isPalindrome(string s) {
//把字符串中大写转化为小写
for(auto&ch :s)
{
if(ch >='A'&& ch <='Z')
{
ch += 32;
}
}
int begin = 0,end = s.size()- 1;
while(begin < end)
{
while(begin < end&& !IsLetter(s[begin]))
++begin;
while(begin < end&& !IsLetter(s[end]))
--end;
if(s[begin] == s[end])
{
++begin;
--end;
}
else
return false;
}
return true;
}
};