Skip to content
LC-0392 Easy LeetCode

392. Is Subsequence

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 48% Topics: Two Pointers, String, Dynamic Programming
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

class Solution(object):
    def isSubsequence(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: bool
        """
        if not s:
            return True

        i = 0
        for c in t:
            if c == s[i]:
                i += 1
            if i == len(s):
                break
        return i == len(s)

Solution from kamyu104/LeetCode-Solutions · MIT