Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c3bc6ef

Browse files
Add solution to leetcode 392
1 parent 1111730 commit c3bc6ef

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎392-Is Subsequence.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Link to problem: https://leetcode.com/problems/is-subsequence/
2+
3+
def isSubsequence(s, t):
4+
s_len, t_len = len(s), len(t)
5+
# If strings are the same length, they must be identical
6+
if s_len == t_len:
7+
return s == t
8+
# If s is longer than t, it cannot be a subsequence
9+
elif s_len > t_len:
10+
return False
11+
12+
# i: s index, j: t index
13+
i,j = 0,0
14+
15+
while i < s_len and j < t_len:
16+
s_char, l_char = s[i], t[j]
17+
if s_char == l_char:
18+
i += 1
19+
j += 1
20+
else:
21+
j += 1
22+
23+
return i >= s_len

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /