[力扣]——125.验证回文串

java 复制代码
class Solution {
    public static boolean isValidChar(char ch){
        if((ch >= 'a' && ch <= 'z') ||
           (ch >= '0' && ch <= '9')){
               return true;
       }
 
        return false;
   }
 
    public boolean isPalindrome(String s) {
    // 将大小写统一起来
        s = s.toLowerCase();
        int left = 0, right = s.length()-1;
        while(left < right){
            // 1. 从左侧找到一个有效的字符
            while(left < right && !isValidChar(s.charAt(left))){
                left++;
           }
 
            // 2. 从右侧找一个有效的字符
            while(left < right && !isValidChar(s.charAt(right))){
                right--;
           }
 
            if(s.charAt(left) != s.charAt(right)){
                return false;
           }else{
                left++;
                right--;
           }
       }
 
        return true;
   }
}
相关推荐
旖-旎20 天前
《LeetCode 417 太平洋大西洋水流问题 FloodFill DFS 解法》
c++·算法·深度优先·力扣·floodfill
旖-旎20 天前
《LeetCode 130 被围绕的区域 FloodFill DFS 解法》
c++·算法·深度优先·力扣·floodfill
旖-旎21 天前
《LeetCode 695 岛屿的最大面积 FloodFill DFS 解法》
c++·算法·力扣·深度优先遍历·floodfill
旖-旎21 天前
《LeetCode 200 FloodFill 岛屿数量DFS解法》
c++·算法·深度优先·力扣·floodfill
旖-旎24 天前
FloodFill(图像渲染)(1)
c++·算法·深度优先·力扣
帅小伙―苏24 天前
239. 滑动窗口最大值
python·力扣
语戚1 个月前
力扣 3161. 块放置查询:线段树解法(Java 实现)
java·算法·leetcode·面试·线段树·力扣·
填满你的记忆1 个月前
《动态规划-基础篇》
算法·动态规划·力扣
做人求其滴1 个月前
面试经典 150 题 380 274
c++·算法·面试·职场和发展·力扣
Lsk_Smion2 个月前
Hot100(开刷) 之 LRU(最近最少使用)缓存
力扣