Skip to content

Commit dba02c8

Browse files
committed
add solution for leetcode prob 392
1 parent 9cacfe6 commit dba02c8

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
class Solution:
22
def isSubsequence(self, s: str, t: str) -> bool:
3-
pc = 0
4-
count = 0
3+
i=0
54
for j in range(0, len(t)):
6-
for it in range(pc, len(s)):
7-
if t[j] == s[it]:
8-
if it == pc or it == pc + 1:
9-
pc = it
10-
count += 1
11-
else:
12-
return False
13-
if count == len(s):
5+
if i < len(s) and s[i] == t[j]:
6+
i += 1
7+
if i == len(s):
148
return True
159
else:
1610
return False
1711

18-
1912
t = 'abcde'
20-
s = 'ace'
13+
s = "bb"
14+
2115
print(Solution().isSubsequence(s, t))

0 commit comments

Comments
 (0)