作者DJYOMIYAHINA (通通打死)
標題Re: [閒聊] 每日leetcode
時間2024-12-04 23:22:04
就greedy找下去
有找到相同or差一個的就先配對掉
寫醜醜
def canMakeSubsequence(self, str1: str, str2: str) -> bool:
i,j = 0,0
while i<len(str1):
if j>=len(str2):
break
if (ord(str2[j])-ord(str1[i]))==1 or (ord(str2[j])-ord(str1[i]))==0
or (ord(str2[j])-ord(str1[i]))==-25:
j += 1
i += 1
return j==len(str2)
--
※ 發信站: 批踢踢實業坊(pttsite.org.tw), 來自: 125.229.37.69 (臺灣)
※ 文章網址: https://pttsite.org.tw/Marginalman/M.1733325726.A.9C8