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 |
반응형
'python-algorithm' 카테고리의 다른 글
백준 1157 단어 공부 (0) | 2023.06.24 |
---|---|
leetcode 242. Valid Anagram (0) | 2023.06.23 |
leetcode 13. Roman to Integer (1) | 2023.06.19 |
leetcode 27. Remove Element (0) | 2023.06.19 |
leetcode 744. Find Smallest Letter Greater Than Target (0) | 2023.06.09 |
댓글