/** * @Description 回文串验证直接使用对撞指针即可 * 这道题其实主要是考察对撞指针的应用和String库函数的应用 * @Date 2022/1/9 6:09 下午 * @Author wuqichuan@zuoyebang.com **/public class Solution { public boolean isPalindrome(String s) { //先把只考虑字符,剔除符号 StringBuffer sgood = new StringBuffer(); int length = s.length(); for (int i = 0; i < length; i++) { char ch = s.charAt(i); if (Character.isLetterOrDigit(ch)) { sgood.append(Character.toLowerCase(ch)); } } int left = 0; int right = sgood.length() - 1; while (left < right) { if (sgood.charAt(left) != sgood.charAt(right)) { return false; } ++left; --right; } return true; }}