LeetCode 392. Is Subsequence

题目

LeetCode 392. Is Subsequence_第1张图片

代码

class Solution:
    def isSubsequence(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: bool
        """
        i = 0; j = 0
        index = 0
        for i in range(len(s)):
            flag = False
            for j in range(index, len(t)):
                if t[j] == s[i]:
                    index = j + 1
                    flag = True
                    break
            if not flag: return False
        return True

你可能感兴趣的:(算法-贪心)