当前位置:网站首页>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
边栏推荐
- GCC usage, makefile summary
- The combination of applet container technology and IOT
- Ouc2021 autumn - Software Engineering - end of term (recall version)
- 【EI会议】2022年国际土木与海洋工程联合会议(JCCME 2022)
- What happens when a function is called before it is declared in C?
- File upload and download
- ECMAScript 6.0
- Leetcode:剑指 Offer 59 - I. 滑动窗口的最大值
- Pyramid Scene Parsing Network【PSPNet】论文阅读
- MFC窗口滚动条用法
猜你喜欢

Download and installation configuration of cygwin

IPv4和IPv6、局域网和广域网、网关、公网IP和私有IP、IP地址、子网掩码、网段、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?

用小程序的技术优势发展产业互联网

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

整合阿里云短信的问题:无法从静态上下文中引用非静态方法

pytorch训练深度学习网络设置cuda指定的GPU可见

MFC窗口滚动条用法

Leetcode 128 longest continuous sequence (hash set)

pytorch nn.AdaptiveAvgPool2d(1)

Processing of menu buttons on the left and contents on the right of the background system page, and double scrolling appears on the background system page
随机推荐
数据库中COMMENT关键字的使用
Bilinear upsampling and f.upsample in pytorch_ bilinear
Detailed explanation of ES6 deconstruction grammar
AfxMessageBox和MessageBox的用法
IPv4 and IPv6, LAN and WAN, gateway, public IP and private IP, IP address, subnet mask, network segment, network number, host number, network address, host address, and IP segment / number - what does
串口接收数据方案设计
Ouc2021 autumn - Software Engineering - end of term (recall version)
Explain spark operation mode in detail (local+standalone+yarn)
Binary tree god level traversal: Morris traversal
Design of serial port receiving data scheme
【伸手党福利】开发人员重装系统顺序
Filter
Review column - message queue
The shell script uses two bars to receive external parameters
FCN full Convolution Network Understanding and Code Implementation (from pytorch Official Implementation)
bootsrap中的栅格系统
Data exchange JSON
Leetcode: offer 59 - I. maximum value of sliding window
不用加减乘除实现加法
TEC: Knowledge Graph Embedding with Triple Context