Python O(|t| + |s|) solution


  • 0
    N
    class Solution(object):
        def isSubsequence(self, s, t):
            i=0
            ctr=0
            if(len(s) > len(t)): return False
            if(len(s)== 0): return True
            while(i < len(s)):
                if(s[i]== t[ctr]):
                    i+=1
                ctr+= 1
                if(ctr == len(t) and i < len(s)):
                    return False
            return True
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.