Q125. Valid Palindrome
分析
C++代码
class Solution {
public:
bool isPalindrome(string s) {
string str;
for(int i = 0; i< s.size(); i++){
if( (s[i]>='a' && s[i]<='z') || (s[i]>='0' && s[i]<='9')) str+=s[i];
if(s[i]>='A' && s[i]<='Z') str+= 'a'+(s[i]-'A');
}
for(int i=0, j = str.size()-1; i<=j;i++,j--){
if(str[i]!=str[j]) return false;
}
return true;
}
};Last updated