728x90
class Solution:
def isSubsequence(self, s: str, t: str) -> bool:
if not s:
return True
i = 0
for c in t:
if c == s[i]:
i += 1
if i == len(s):
return True
return False
i를 pointer로 사용해서 relative position 위치 정보를 고려해서 순차적으로
i를 하나씩 업데이트
다 찾은 경우 (i==len(s)) return.
출처: github.com/jiapengwen/LeetCode/blob/master/Python/is-subsequence.py
728x90
'Leetcode' 카테고리의 다른 글
[LeetCode] Longest Palindrome 파이썬 (bitwise &, Counter) (0) | 2021.04.16 |
---|---|
[LeetCode] Sum of Left Leaves 파이썬 (Tree) (0) | 2021.04.15 |
[LeetCode] Find the Difference 파이썬 (Counter, A.subtract(B), bit operation, xor, reduce) (0) | 2021.04.14 |
[LeetCode] First Unique Character in a String 파이썬 (Counter, str.find) (0) | 2021.04.14 |
[LeetCode] Ransom Note 파이썬 (dict, set, count) (0) | 2021.04.14 |
댓글