392. 判断子序列
作者:互联网
392. 判断子序列
解题思路
使用双指针进行判断,当遇到不同元素时长指针加一,否则长短指针均加一。
代码
def isSubsequence(self, s: str, t: str) -> bool:
if s == '':
return True
ps = 0
pt = 0
while ps < len(s) and pt < len(t):
if s[ps] == t[pt]:
if ps == len(s) - 1:
return True
ps += 1
pt += 1
return False
运行结果
标签:ps,判断,return,pt,len,392,序列,指针 来源: https://blog.csdn.net/weixin_45982067/article/details/121061310