python (贪心算法)判断是否是子序列

描述:

给定字符串 s 和 t ,判断 s 是否为 t 的子序列。

整体思路:

循环s子序列,判断s中的所有字符都会按照顺序出现在t中

class Solution:
    def isSubsequence(self, s: str, t: str) -> bool:
        index = 0
        for value in s:
            index = t.find(value, index)
            if index == -1:
                return False
            index += 1
        return True
posted @ 2019-11-29 22:30  Fancey  阅读(1048)  评论(0)    收藏  举报