Re: [閒聊] 每日leetcode
2825. Make String a Subsequence Using Cyclic Increments
## 思路
用pointer i 紀錄目前對應的str2字元
掃str1比對對應的str2字元 有match就i+1
如果指標到底就回傳TRUE
## CODE
```python
class Solution:
def canMakeSubsequence(self, str1: str, str2: str) -> bool:
next_char = {}
for i in range(25):
next_char[chr(ord('a') + i)] = chr(ord('a') + i + 1)
next_char['z'] = 'a'
i = 0
for ch in str1:
if str2[i] == ch or str2[i] == next_char[ch]:
i += 1
if i == len(str2):
return True
return False
```
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 94.156.205.137 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1733315896.A.F37.html
討論串 (同標題文章)
完整討論串 (本文為第 1178 之 1548 篇):