首页 > 其他分享 >【双指针】LeetCode 125. 验证回文串

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

时间:2023-01-27 18:55:09浏览次数:65  
标签:ch StringBuffer sgood length 125 LeetCode 回文

题目链接

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());
    }
}

标签:ch,StringBuffer,sgood,length,125,LeetCode,回文
From: https://www.cnblogs.com/shixuanliu/p/17069171.html

相关文章