VISUALGO//PROBLEMS
is subsequence · two pointerseasy
s (find this)
a
b
c
t (search in)
a
h
b
g
d
c
result
·
ELEMENTS
s
t
Python
def isSubsequence(s: str, t: str) -> bool:
si, ti = 0, 0
while si < len(s) and ti < len(t):
if s[si] == t[ti]:
si += 1
ti += 1
return si == len(s)