https://leetcode-cn.com/problems/valid-palindrome/
public boolean isPalindrome(String s) {if (s.length() == 0) {return true;}char[] str = s.toCharArray();int L = 0;int R = s.length() - 1;while (L < R) {while (L < R && !Character.isLetterOrDigit(str[L])) {++L;}while (L < R && !Character.isLetterOrDigit(str[R])) {--R;}if (Character.toLowerCase(str[L]) != Character.toLowerCase(str[R])) {return false;}++L;--R;}return true;}
另一个版本,不用Character类
public static boolean isPalindrome(String s) {if (s == null || s.length() == 0) {return true;}char[] str = s.toCharArray();int L = 0;int R = str.length - 1;while (L < R) {if (validChar(str[L]) && validChar(str[R])) {if (!equal(str[L], str[R])) {return false;}L++;R--;} else {L += validChar(str[L]) ? 0 : 1;R -= validChar(str[R]) ? 0 : 1;}}return true;}public static boolean validChar(char c) {return isLetter(c) || isNumber(c);}public static boolean equal(char c1, char c2) {if (isNumber(c1) || isNumber(c2)) {return c1 == c2;}return (c1 == c2) || (Math.max(c1, c2) - Math.min(c1, c2) == 32);}public static boolean isLetter(char c) {return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');}public static boolean isNumber(char c) {return (c >= '0' && c <= '9');}
