Example 1:
Input: s = "abc", t = "ahbgdc"
Output: true
Example 2:
Input: s = "axc", t = "ahbgdc"
Output: false
class Solution:
def isSubsequence(self, s: str, t: str) -> bool:
pointer, cnt = 0, 0
for i in range(len(s)):
for j in range(pointer,len(t)):
# 같은 문자가 존재할 때 카운팅, 그 다음 문자부터 탐색
if s[i] == t[j]:
pointer = j+1
cnt += 1
break
if cnt != len(s) :
return False
return True
'Python 문제풀이 > LeetCode' 카테고리의 다른 글
206. Reverse Linked List ** (0) | 2022.08.15 |
---|---|
21. Merge Two Sorted Lists (0) | 2022.08.15 |
205. Isomorphic Strings (0) | 2022.08.11 |
724. Find Pivot Index (0) | 2022.08.09 |
1480. Running Sum of 1d Array (0) | 2022.08.09 |