判斷s是不是t的子串(字符不需要連續(xù)),水題
1 #392
2 #Runtime: 8 ms (Beats 94.61%)
3 #Memory: 13.3 MB (Beats 96%)
4
5 class Solution(object):
6 def isSubsequence(self, s, t):
7 """
8 :type s: str
9 :type t: str
10 :rtype: bool
11 """
12 p = 0
13 for ch in s:
14 while p < len(t) and t[p] != ch:
15 p += 1
16 if p >= len(t):
17 return False
18 if t[p] == ch:
19 p += 1
20 return True