-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsSubsequence
More file actions
19 lines (15 loc) · 806 Bytes
/
IsSubsequence
File metadata and controls
19 lines (15 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#Given two strings s and t, return true if s is a subsequence of t, or false otherwise.
#A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing
#the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not).
class Solution:
def isSubsequence(self, s: str, t: str) -> bool:
s_length = 0
for i in t:
if s_length < len(s):
if i == s[s_length]:
s_length += 1
if s_length == len(s):
return True
else:
return False
#Instead of if/else statement at end get used to "return: s_length==len(s)" this will return True or False based on condition