We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9cacfe6 commit dba02c8Copy full SHA for dba02c8
leetcode/python/Dynamic Programming/392.is_subsequence.py
@@ -1,21 +1,15 @@
1
class Solution:
2
def isSubsequence(self, s: str, t: str) -> bool:
3
- pc = 0
4
- count = 0
+ i=0
5
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):
+ if i < len(s) and s[i] == t[j]:
+ i += 1
+ if i == len(s):
14
return True
15
else:
16
return False
17
18
-
19
t = 'abcde'
20
-s = 'ace'
+s = "bb"
+
21
print(Solution().isSubsequence(s, t))
0 commit comments