Uriel's Corner

Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
posts - 0, comments - 50, trackbacks - 0, articles - 594
判断s是不是t的子串(字符不需要连续),水题

 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

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理