Leetcode Is Subsequence

Posted lettuan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode Is Subsequence相关的知识,希望对你有一定的参考价值。

本题的思路比较简答,设置一个计数器,在scan list t的过程中,每发现一个s里面的字母,计数器就+1。如果计数器等于s的长度,说明已经找到一个subsequence 等于s。

 1 class Solution(object):
 2     def isSubsequence(self, s, t):
 3         """
 4         :type s: str
 5         :type t: str
 6         :rtype: bool
 7         """
 8         if not s:
 9             return True
10         i = 0
11         for c in t:
12             if c == s[i]:
13                 i += 1
14             if i == len(s):
15                 return True
16         
17         return False

 

以上是关于Leetcode Is Subsequence的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode | 0392. Is Subsequence判断子序列Python

LeetCode --- 392. Is Subsequence 解题报告

Leetcode Is Subsequence

[leetcode-392-Is Subsequence]

LeetCode 392. Is Subsequence

[LeetCode] 392. Is Subsequence Java