先把字母数不同的先剃掉 会比较好做
剩下就两个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