Re: [閒聊] 每日leetcode
先把字母數不同的先剃掉 會比較好做
剩下就兩個pointer check一下
寫了一堆條件
懶得整理了
def canChange(self, start: str, target: str) -> bool:
# check
start_2, target_2 = start, target
if len(start_2.replace("_", "")) != len(target_2.replace("_", "")):
return False
n = len(start)
i,j = 0,0
while i<n and j<n:
while i<n and start[i] == '_':
i += 1
while j<n and target[j] == '_':
j += 1
if i>=n and j>=n:
break
elif start[i] != target[j]:
return False
elif i<j and start[i]=='L':
return False
elif i>j and start[i]=='R':
return False
i, j = i+1, j+1
return True
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.37.69 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1733406400.A.BD6.html
※ 編輯: DJYOMIYAHINA (125.229.37.69 臺灣), 12/05/2024 21:47:25
推
12/05 21:47,
1年前
, 1F
12/05 21:47, 1F
討論串 (同標題文章)
完整討論串 (本文為第 1183 之 1548 篇):