Skip to content

Instantly share code, notes, and snippets.

@wushbin
Created February 16, 2020 02:06
Show Gist options
  • Save wushbin/632925c21125c497e88ecc21952208b5 to your computer and use it in GitHub Desktop.
Save wushbin/632925c21125c497e88ecc21952208b5 to your computer and use it in GitHub Desktop.
class Solution {
public boolean isPalindrome(String s) {
int l = 0;
int r = s.length() - 1;
while(l < r) {
while(l < r && !Character.isLetter(s.charAt(l)) && !Character.isDigit(s.charAt(l)) ) {
l++;
}
char lc = Character.toLowerCase(s.charAt(l));
while(r > l && !Character.isLetter(s.charAt(r)) && !Character.isDigit(s.charAt(r)) ) {
r--;
}
char rc = Character.toLowerCase(s.charAt(r));
if (lc != rc) {
return false;
}
l++;
r--;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment