125. Valid Palindrome#
Code#
1public boolean isPalindrome(String s) {
2 int l = 0, r = s.length() - 1;
3
4 while (l <= r) {
5 char lc = s.charAt(l), rc = s.charAt(r);
6
7 if (!Character.isLetterOrDigit(lc)) {
8 l++;
9 continue;
10 }
11
12 if (!Character.isLetterOrDigit(rc)) {
13 r--;
14 continue;
15 }
16
17 if (Character.toLowerCase(lc) != Character.toLowerCase(rc)) {
18 return false;
19 }
20
21 l++;
22 r--;
23 }
24
25 return true;
26}