Problem Link
https://leetcode.com/problems/valid-palindrome/
Detailed Step-by-Step Explanation
https://leetcode.com/problems/valid-palindrome/solutions/7446986/most-optimal-approach-beats-100-two-poin-uoy9

Solution
class Solution {
public boolean isPalindrome(String s) {
s = s.toLowerCase();
int left = 0;
int right = s.length() - 1;
while (left < right) {
char chLeft = s.charAt(left);
char chRight = s.charAt(right);
if (!(chLeft >= 'a' && chLeft <= 'z' || chLeft >= '0' && chLeft <= '9')) {
left++;
continue;
}
if (!(chRight >= 'a' && chRight <= 'z' || chRight >= '0' && chRight <= '9')) {
right--;
continue;
}
if (chLeft != chRight) {
return false;
}
left++;
right--;
}
return true;
}
}
Top comments (0)