当前位置:网站首页>392. 判断子序列
392. 判断子序列
2022-07-01 03:23:00 【Sun_Sky_Sea】
392. 判断子序列
原始题目链接:https://leetcode.cn/problems/is-subsequence/
给定字符串 s 和 t ,判断 s 是否为 t 的子序列。
字符串的一个子序列是原始字符串删除一些(也可以不删除)字符而不改变剩余字符相对位置形成的新字符串。(例如,"ace"是"abcde"的一个子序列,而"aec"不是)。
进阶:
如果有大量输入的 S,称作 S1, S2, … , Sk 其中 k >= 10亿,你需要依次检查它们是否为 T 的子序列。在这种情况下,你会怎样改变代码?
示例 1:
输入:s = “abc”, t = “ahbgdc”
输出:true
示例 2:
输入:s = “axc”, t = “ahbgdc”
输出:false
提示:
0 <= s.length <= 100
0 <= t.length <= 10^4
两个字符串都只由小写字符组成。
解题思路:
两个指针,分别只想s和t,相同字符分别自增两个指针,不同,则继续看后面的t的字符,如果最后s能够遍历结束,则表示s是t的子串。
代码实现:
class Solution:
def isSubsequence(self, s: str, t: str) -> bool:
m, n = len(s), len(t)
i = j = 0
while i < m and j < n:
if s[i] == t[j]:
i += 1
j += 1
return i == m
边栏推荐
- Keil5中如何做到 0 Error(s), 0 Warning(s).
- Leetcode 1482 guess, how about this question?
- Database DDL (data definition language) knowledge points
- Golang multi graph generation gif
- shell脚本使用两个横杠接收外部参数
- 318. 最大单词长度乘积
- FCN全卷積網絡理解及代碼實現(來自pytorch官方實現)
- Ridge regression and lasso regression
- Sort linked list (merge sort)
- Jeecgboot output log, how to use @slf4j
猜你喜欢

Feature Pyramid Networks for Object Detection论文理解

Avalanche problem and the use of sentinel

RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs

pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear

后台系统右边内容如何出现滚动条和解决双滚动条的问题

jeecgboot输出日志,@Slf4j的使用方法

过滤器 Filter

4、【WebGIS实战】软件操作篇——数据导入及处理

后台系统页面左边菜单按钮和右边内容的处理,后台系统页面出现双滚动

Pytorch training deep learning network settings CUDA specified GPU visible
随机推荐
Blueprism registration, download and install -rpa Chapter 1
网页不能右键 F12 查看源代码解决方案
10、Scanner. Next() cannot read spaces /indexof -1
Bilinear upsampling and f.upsample in pytorch_ bilinear
线程数据共享和安全 -ThreadLocal
Cookie&Session
Test function in pychram
Edlines: a real time line segment detector with a false detection control
5、【WebGIS实战】软件操作篇——服务发布及权限管理
389. 找不同
Appium automation test foundation -- supplement: c/s architecture and b/s architecture description
Cookie&Session
Md5sum operation
FCN全卷积网络理解及代码实现(来自pytorch官方实现)
完全背包问题
409. 最长回文串
242. 有效的字母异位词
Download and installation configuration of cygwin
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
AfxMessageBox和MessageBox的用法