The code is in the following link:
https://leetcode.com/problems/is-subsequence/
My code:
class Solution:
def isSubsequence(self, s: str, t: str) -> bool:
if len(s) == 0:
return True
elif len(t) == 1:
if s[0] == t[0]:
return True
else:
return False
else:
i = 0
CheckNum = 0
while i< len(t):
if s[CheckNum] == t[i]:
CheckNum +=1
if CheckNum == len(s):
return True
i+=1
return False
Explanation:
Check one by one, if one element is confirmed, then we check next element in the string s. If the total all the element in the string s occur in string t, then we return true, otherwise we return false.