2337. Move Pieces to Obtain a String ## 思路 two pointer 每次loop 檢查跳過`_`後遇到的字元 如果字元一樣, 就再檢查index R: 右移 (idx_start <= idx_target L: 左移 (idx_start >= idx_target ## Code ```python class Solution: def canChange(self, start: str, target: str) -> bool: n = len(start) i = j = 0 while True: while i < n and start[i] == '_': i += 1 while j < n and target[j] == '_': j += 1 if i == n or j == n: break if start[i] != target[j]: return False if start[i] == 'L' and i < j: return False if start[i] == 'R' and i > j: return False i += 1 j += 1 return i == j == n ``` -- ※ 發信站: 批踢踢實業坊(pttsite.org.tw), 來自: 84.17.37.73 (香港) ※ 文章網址: https://pttsite.org.tw/Marginalman/M.1733403836.A.46F