双指针涉及到leetcode

1. 背景

双指针可以巧妙解决一些leetcode的算法问题,做个总结方便自己做出一些规律总结,方便举一反三

2. demo

2.1 392. 判断子序列

给定字符串 st ,判断 s 是否为 t 的子序列。

ini 复制代码
public class Leetcode392Bak {
    public boolean isSubsequence(String s, String t) {
        int length = t.length();
        int j = 0;
        for (int i = 0; i < length && j < s.length() ; i++) {
            if (t.charAt(i) == s.charAt(j)){
                j ++;
            }
        }
        return j == s.length();
    }
}

des: 一定要预防短的指针产生index out of range的情况

相关推荐
踏浪无痕24 分钟前
SQLInsight:从JDBC底层到API调用的零侵入SQL监控方案
数据库·后端·开源
superman超哥1 小时前
Rust HashSet与BTreeSet的实现细节:集合类型的底层逻辑
开发语言·后端·rust·编程语言·rust hashset·rust btreeset·集合类型
superman超哥2 小时前
Rust String与&str的内部实现差异:所有权与借用的典型案例
开发语言·后端·rust·rust string·string与str·内部实现·所有权与借用
愈努力俞幸运3 小时前
rust安装
开发语言·后端·rust
踏浪无痕3 小时前
JobFlow 负载感知调度:把任务分给最闲的机器
后端·架构·开源
UrbanJazzerati3 小时前
Python自动化统计工具实战:Python批量分析Salesforce DML操作与错误处理
后端·面试
我爱娃哈哈3 小时前
SpringBoot + Seata + Nacos:分布式事务落地实战,订单-库存一致性全解析
spring boot·分布式·后端
nil3 小时前
记录protoc生成代码将optional改成omitepty问题
后端·go·protobuf
superman超哥4 小时前
Rust 范围模式(Range Patterns):边界检查的优雅表达
开发语言·后端·rust·编程语言·rust范围模式·range patterns·边界检查
云上凯歌4 小时前
02 Spring Boot企业级配置详解
android·spring boot·后端