7.Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Examples
Input: "A man, a plan, a canal: Panama"
Output: true
Input: "race a car"
Output: falseSolution:-
class Solution {
public:
bool isPalindrome(string s) {
if(s==""){return true;}
int start = 0;
int end = s.length()-1;
bool res = true;
while(start<=end){
int x = tolower(s[start]);
int y = tolower(s[end]);
if(x<97||x>122){
if(x<48||x>57){
start++;
continue;
}
}
if(y<97||y>122){
if(y<48||y>57){
end--;
continue;
}
}
if(x!=y){
res = false;
break;
}
start++;
end--;
}
return res;
}
};Valid Palindrome II:
Solution:
Last updated