当前位置:网站首页>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
边栏推荐
- Unexpected token o in JSON at position 1 ,JSON解析问题
- Server rendering technology JSP
- 数据交换 JSON
- Use of comment keyword in database
- How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
- Cookie&Session
- The combination of applet container technology and IOT
- GCC usage, makefile summary
- 10、Scanner. Next() cannot read spaces /indexof -1
- Cygwin的下载和安装配置
猜你喜欢

The combination of applet container technology and IOT

Addition without addition, subtraction, multiplication and division

Cookie&Session

Server rendering technology JSP

Cygwin的下载和安装配置

Take you through a circuit board, from design to production (dry goods)

FCN full Convolution Network Understanding and Code Implementation (from pytorch Official Implementation)

使用selenium自动化测试工具爬取高考相关院校专业招生分数线及排名情况

Thread data sharing and security -threadlocal

Asgnet paper and code interpretation 2
随机推荐
【伸手党福利】JSONObject转String保留空字段
torch. histc
Pytorch training deep learning network settings CUDA specified GPU visible
pytorch nn. AdaptiveAvgPool2d(1)
【伸手党福利】开发人员重装系统顺序
Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)
Detailed explanation of ES6 deconstruction grammar
4、【WebGIS实战】软件操作篇——数据导入及处理
Valid brackets (force deduction 20)
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
Go tool cli for command line implementation
IPv4和IPv6、局域网和广域网、网关、公网IP和私有IP、IP地址、子网掩码、网段、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?
shell脚本使用两个横杠接收外部参数
Download and installation configuration of cygwin
Learning notes for introduction to C language multithreaded programming
小程序容器技术与物联网IoT的结合点
报错:Plug-ins declaring extensions or extension points must set the singleton directive to true
10、Scanner.next() 无法读取空格/indexOf -1
Use of comment keyword in database
后台系统右边内容如何出现滚动条和解决双滚动条的问题