1. /**
    2. * @Description 回文串验证直接使用对撞指针即可
    3. * 这道题其实主要是考察对撞指针的应用和String库函数的应用
    4. * @Date 2022/1/9 6:09 下午
    5. * @Author wuqichuan@zuoyebang.com
    6. **/
    7. public class Solution {
    8. public boolean isPalindrome(String s) {
    9. //先把只考虑字符,剔除符号
    10. StringBuffer sgood = new StringBuffer();
    11. int length = s.length();
    12. for (int i = 0; i < length; i++) {
    13. char ch = s.charAt(i);
    14. if (Character.isLetterOrDigit(ch)) {
    15. sgood.append(Character.toLowerCase(ch));
    16. }
    17. }
    18. int left = 0;
    19. int right = sgood.length() - 1;
    20. while (left < right) {
    21. if (sgood.charAt(left) != sgood.charAt(right)) {
    22. return false;
    23. }
    24. ++left;
    25. --right;
    26. }
    27. return true;
    28. }
    29. }