Re: [閒聊] 每日leetcode

看板Marginalman作者 (通通打死)時間1年前 (2024/12/05 21:46), 1年前編輯推噓1(100)
留言1則, 1人參與, 1年前最新討論串1183/1548 (看更多)
先把字母數不同的先剃掉 會比較好做 剩下就兩個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
文章代碼(AID): #1dKQx0lM (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dKQx0lM (Marginalman)