https://leetcode.com/problems/valid-palindrome/description/
bool isPalindrome(string s) {
if(s.size()<2) return true;
for(int i=0, j=s.size()-1; i<j;) {
char a = tolower(s[i]);
char b = tolower(s[j]);
if(!(a>='a'&&a<='z') && !(a>='0'&&a<='9')) { i++; continue;}
if(!(b>='a'&&b<='z') && !(b>='0'&&b<='9')) { j--; continue;}
if(a!=b) return false;
i++;
j--;
}
return true;
}
No comments:
Post a Comment