You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tech-interview-handbook/utilities/python/is_subsequence.py

14 lines
289 B

7 years ago
def is_subsequence(s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
if len(s) > len(t):
return False
matched_s = 0
for char in t:
if matched_s < len(s) and s[matched_s] == char:
matched_s += 1
return matched_s == len(s)