Created
February 16, 2020 02:06
-
-
Save wushbin/632925c21125c497e88ecc21952208b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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