【双指针】LeetCode 125. 验证回文串

题目链接

125. 验证回文串

思路

简单双指针应用

代码

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));
            }
        }
        StringBuffer sgood_rev = new StringBuffer(sgood).reverse();

        return sgood.toString().equals(sgood_rev.toString());
    }
}

拓展

【双指针】LeetCode 680. 验证回文串 II

posted @ 2023-01-27 18:49  Frodo1124  阅读(35)  评论(0编辑  收藏  举报