Posted on 2023-09-22 13:38
Uriel 阅读(24)
评论(0) 编辑 收藏 引用 所属分类:
闲来无事重切Leet Code 、
大水题
判断s是不是t的子串(字符不需要连续),水题
1 #392
2 #Runtime: 8 ms (Beats 94.61%)
3 #Memory: 13.3 MB (Beats 96%)
4
5 class Solution(object):
6 def isSubsequence(self, s, t):
7 """
8 :type s: str
9 :type t: str
10 :rtype: bool
11 """
12 p = 0
13 for ch in s:
14 while p < len(t) and t[p] != ch:
15 p += 1
16 if p >= len(t):
17 return False
18 if t[p] == ch:
19 p += 1
20 return True