December 04, 2024
์ด ๋ฌธ์ ๋ ๋ฌธ์์ด str1์ str2๊ฐ ์ฃผ์ด์ก์๋, str1์ ๋ฌธ์๋ฅผ 1์นธ ์ฆ๊ฐํ์ฌ str2๊ฐ subsequence๊ฐ ๋๋๋ก ๋ง๋ค ์ ์๋์ง ์ฌ๋ถ๋ฅผ ํ๋จํ๋ ๋ฌธ์ ์ด๋ค.
class Solution:
def canMakeSubsequence(self, str1: str, str2: str) -> bool:
index = 0
for char in str1:
next_char = 'a' if char == 'z' else chr(ord(char)+1)
if index < len(str2) and str2[index] in (char, next_char):
index += 1
return index == len(str2)
Constraints:
1 <= str1.length <= 10^5
1 <= str2.length <= 10^5
str1 and str2 consist of only lowercase English letters.