Python 문제풀이/LeetCode

392. Is Subsequence

hjc_ 2022. 8. 11. 02:40

link

 

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