【LeetCode】392. Is Subsequence

字符串序列判定(100%用例)C卷 (Java&&Python&&Node.js&&C语言&&C++) 输入两个字符串 S 和 L ,都只包含英文小写字母。S 长度 阅读详情

392. Is Subsequence

Given a string s and a string t, check if s is subsequence of t.

You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) string, and s is a short string (<=100).

A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ace" is a subsequence of "abcde" while "aec" is not).

Example 1:
s = "abc", t = "ahbgdc"

Return true.

Example 2:
s = "axc", t = "ahbgdc"

Return false.

Follow up:
If there are lots of incoming S, say S1, S2, ... , Sk where k >= 1B, and you want to check one by one to see if T has its subsequence. In this scenario, how would you change your code?

Credits:
Special thanks to @pbrother for adding this problem and creating all test cases.

class Solution {
public:
    bool isSubsequence(string s, string t) {
        int idx = 0;
        for (int i = 0; i < t.size(); i++) {
            if (s[idx] == t[i]) {
                idx++;
            }
        }
        return idx == s.size();
    }
};

 

【华为OD真题 Python】字符串序列判定 判定规则:S中的每个字符在L中都能找到(可以不连续),且S在L中字符的前后顺序与S中顺序要保持一致。(例如,S="ace"是L="abcde"的一个子序列且有效字符是a、c、e,而"aec"不是有效子序列,且有效字符只有a、e)输入两个字符串S和L,都只包含英文小写字母。S长度 阅读详情

相关推荐

电表协议避坑指南:DLT645-2007与Modbus RTU的5大核心差异对比

本文深入对比了DLT645-2007与Modbus RTU两大电表通讯协议的核心差异,涵盖协议定位、数据地址、报文结构及实测性能。DLT645-2007作为电力行业标准,数据定义统一但效率受限;Modbus RTU作为通用协议,灵活高效但需依赖厂家点表。文章结合实测数据与开发经验,为不同场景下的协议选型与编程实践提供了清晰的避坑指南。

weixin_29166013的博客 107

【JS】判断是不是字符串子序列

定两个字符串 s和 t ,判断 s是否为 t 的子序列。 你可以认为 s 和 t 中仅包含英文小写字母。字符串 t 可能会很长(长度n ~= 500,000),而 s 是个短字符串(长度

倏存的博客 551

博图HMI多语言文本列表一键生成攻略:从Excel模板到TIA Portal的完整流程

本文详细介绍了如何利用Excel模板和TIA Portal API实现博图HMI多语言文本列表的一键生成。通过标准化Excel模板设计、解析TIA Portal的XML结构,并结合C#代码实现自动化导入,大幅提升多语言项目的开发效率。特别适用于需要支持多语言版本的自动化设备HMI界面开发。

weixin_26934905的博客 218

字符串序列判定

S 中的每个字符在 L 中都能找到(可以不连续),且 S 在L中字符的前后顺序与 S 中顺序要保持一致。输入两个字符串 S 和 L,都只包含英文小写字母。`S 长度

南京大学软件工程硕士在读 1143

【HarmonyOS 5】鸿蒙APP使用【团结引擎Unity】开发的案例教程

以下是基于团结引擎开发鸿蒙Unity应用的详细案例教程,整合环境配置、工程适配、跨语言通信等核心环节。

2201_75709314的博客 2482

4G LTE 与 5G 无线网络规划对比:从 BBU/RRU 到 CU/DU/AAU 的架构演进解析

本文深度解析4G LTE与5G无线网络架构的演进差异,从BBU/RRU分立式架构到CU/DU/AAU三级重构,揭示移动通信代际跃迁的技术本质。重点对比了网络规划中的覆盖能力、容量规划、传输网络等九大维度,为通信工程师提供实用的技术对照手册,助力5G网络高效部署。

weixin_32821533的博客 287

Leetcode 392.判断子序列(Is Subsequence)

Leetcode 392.判断子序列 1 题目描述(Leetcode题目链接)   给定字符串 s 和 t ,判断 s 是否为 t 的子序列。 你可以认为 s 和 t 中仅包含英文小写字母。字符串 t 可能会很长(长度 ~= 500,000),而 s 是个短字符串(长度 <=100)。 字符串的一个子序列是原始字符串删除一些(也可以不删除)字符而不改变剩余字符相对位置形成的新字符串。(例如,"ace"是"abcde"的一个子序列,而"aec"不是)。 示例 1: s = “abc”, t = “ahb

qq_39378221的博客 215

26版SPSS操作教程(高级教程第十章)

#大道之行,在于坚持 #本期内容:二分类Logistic回归模型 #由于导师最近布置了学习SPSS这款软件的任务,因此想来平台和大家一起交流下学习经验,这期推送内容接上一次高级教程第九章的学习笔记,希望能得到一些指正和帮助~

你好! 1599

Leetcode 392. Is Subsequence

Leetcode 392. Is Subsequence Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long ...

fengran_mark的博客 176

自然语言处理6 -- 情感分析

1 概述 情感分析是自然语言处理中常见的场景,比如淘宝商品评价,饿了么外卖评价等,对于指导产品更新迭代具有关键性作用。通过情感分析,可以挖掘产品在各个维度的优劣,从而明确如何改进产品。比如对外卖评价,可以分析菜品口味、送达时间、送餐态度、菜品丰富度等多个维度的用户情感指数,从而从各个维度上改进外卖服务。 情感分析可以采用基于情感词典的传统方法,也可以采用基于深度学习的方法,下面详细讲解 ...

谢杨易的博客 5万+

手把手教你学Simulink——基于传统电网建模与稳定性分析的场景实例:基于同步发电机的单机无穷大系统建模与稳定性分析

本文详细介绍了使用MATLAB/Simulink进行单机无穷大系统(SMIB)建模与稳定性分析的方法。教程从系统结构设计入手,包含同步发电机、输电线路、无穷大母线等核心模块的建模步骤和参数配置示例。重点讲解了七个关键步骤:项目创建、模块配置、控制系统集成、负载添加(可选)以及仿真运行与结果分析,并提供了具体的MATLAB代码示例。最后通过性能评估指标(功角差、电压跌落、频率偏差)分析系统稳定性,为电力系统动态特性研究提供了实用指导,强调准确参数设置对仿真结果的重要性。

MHD0815的博客 298

LeetCode OJ-392.Is Subsequence

LeetCode OJ-392.Is Subsequence题目描述 Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and t. t is potentially

oYinGui1 686

24、交通信号协调算法与模型解析

本文深入解析了交通信号协调中的关键算法与模型,包括多路径进展模型、MAXBAND网络系统模型和松弛启用带模型。这些模型通过合理安排相位序列、优化绿波带宽等方式,提高了交通运行的效率。文章还探讨了交通控制从单点控制向网络协调的发展趋势,分析了当前面临的挑战与机遇,并提出了未来研究方向,如借助信息技术和机器学习,深入研究交通网络的基本构成,以实现智能化和精准化的信号协调。

agile9scrum的博客 134

LeetCode: 392. Is Subsequence

题目: LeetCode: 392. Is Subsequence(https://leetcode.com/problems/is-subsequence/description/) class Solution { public boolean isSubsequence(String s, String t) { int currentLoc = 0; byte[] byte...

majinliang1234的博客 200

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Leetcode 392 Is Subsequence

Leetcode 392 Is SubsequenceDescriptioniven a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and t. t is potentially a v

Zeongwan的博客 282

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

LeetCode //C - 392. Is Subsequence

【代码】LeetCode //C - 392. Is Subsequence。

Made in Code 1024

【Leetcode】392. Is Subsequence

【代码】【Leetcode】392. Is Subsequence。

数学、算法爱好者的博客 188

leetcode 392. Is Subsequence

Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) string, ...

蓝羽飞鸟的博客 221

LeetCode 392. Is Subsequence

392. Is SubsequenceGiven a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~=

mingjc的博客 347

[leetcode]392. Is Subsequence

[leetcode]392. Is Subsequence Analysis 早鸭—— [每天刷题并不难0.0] Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and...

weixin_32135877的博客 167

LeetCode 392 Is Subsequence

Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) string,

几百个测试用例一致通过 251

【LeetCode】392. Is Subsequence

题目: Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,0

gmr_vhp的博客 348

LeetCode 392. Is Subsequence 解题报告

LeetCode 392. Is Subsequence 解题报告

骆小坑的填坑之旅 1428

LeetCode 392 is subsequence

脑子秀逗了,看过的题目做的时候还是会忘记。晚上笔试的时候遇到判断是否为字符子串的问题。其实自己之前就在LeetCode上做过,但是!!!丝毫!!没有印象!!!而且!!!这道题很简单的啊!小拳拳锤我胸口! 下面进入正题: Given a string s and a string t, check if s is subsequence of t. You may ass...

暗时间 240
上一篇: 【LeetCode】455. Assign Cookies
下一篇: 马的遍历(回溯+DFS)
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值