python-algorithm

leetcode 392. Is Subsequence

무적김두칠 2023. 6. 19. 00:55

https://leetcode.com/problems/is-subsequence/description/?envType=study-plan-v2&envId=top-interview-150 

 

Is Subsequence - LeetCode

Can you solve this real interview question? Is Subsequence - Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence of a string is a new string that is formed from the original string by deleting some (can be n

leetcode.com

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution:
    def isSubsequence(self, s: str, t: str-> bool:
        check_string = ''
        start_idx = 0
 
        for some_string in t:
            if start_idx == len(s):
                return True
                
            if some_string == s[start_idx]:
                check_string += some_string
                start_idx += 1
        
        if s == check_string:
            return True
        else:
            return False
cs
반응형