当前位置:网站首页>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
边栏推荐
- 静态库使用MFC和共享库使用MFC的区别
- Ultimate dolls 2.0 | encapsulation of cloud native delivery
- What happens when a function is called before it is declared in C?
- Thread data sharing and security -threadlocal
- Avalanche problem and the use of sentinel
- Use of comment keyword in database
- Learning notes for introduction to C language multithreaded programming
- Blueprism registration, download and install -rpa Chapter 1
- 完全背包问题
- leetcode 1482 猜猜看啊,这道题目怎么二分?
猜你喜欢

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

Edlines: a real time line segment detector with a false detection control

ASGNet论文和代码解读2

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

Explain spark operation mode in detail (local+standalone+yarn)

Gorilla/mux framework (RK boot): RPC error code design

Pytorch training deep learning network settings CUDA specified GPU visible

Ultimate dolls 2.0 | encapsulation of cloud native delivery

家居网购项目

后台系统页面左边菜单按钮和右边内容的处理,后台系统页面出现双滚动
随机推荐
Leetcode: offer 59 - I. maximum value of sliding window
shell脚本使用两个横杠接收外部参数
10、Scanner.next() 无法读取空格/indexOf -1
深度学习中的随机种子torch.manual_seed(number)、torch.cuda.manual_seed(number)
【EI检索】2022年第六届材料工程与先进制造技术国际会议(MEAMT 2022)重要信息会议网址:www.meamt.org会议时间:2022年9月23-25日召开地点:中国南京截稿时间:2
Asgnet paper and code interpretation 2
[party benefits] jsonobject to string, leave blank
快速筛选打卡时间日期等数据:EXCEL筛选查找某一时间点是否在某一时间段内
TEC: Knowledge Graph Embedding with Triple Context
Feature pyramid networks for object detection
ASGNet论文和代码解读2
Unexpected token o in JSON at position 1 ,JSON解析问题
Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
LeetCode 144二叉树的前序遍历、LeetCode 114二叉树展开为链表
Database DDL (data definition language) knowledge points
Pathmeasure implements loading animation
Idea plug-in backup table
How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)
File upload and download