392.Is Subsequence
My code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution:
def isSubsequence(self, s: str, t: str) -> bool:
i = 0
if s == "":
return True
for c in t:
if c == s[i]:
i += 1
if i == len(s):
return True
return False
Other code
1
2
3
4
5
6
7
class Solution:
def isSubsequence(self, s: str, t: str) -> bool:
for c in s:
i = t.find(c)
if i == -1: return False
else: t = t[i+1:]
return True