先把字母數不同的先剃掉 會比較好做 剩下就兩個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 elif i==j and start[i]!=target[j]: return False i, j = i+1, j+1 return True -- ※ 發信站: 批踢踢實業坊(pttsite.org.tw), 來自: 125.229.37.69 (臺灣) ※ 文章網址: https://pttsite.org.tw/Marginalman/M.1733406400.A.BD6
oin1104: 大師 12/05 21:47