本帖最后由 fan1993423 于 2020-4-11 11:09 编辑
这样也许快点,版主可以在测一下,速度可能有所提升, @zltzltdef daily369(start: str, end: str) -> bool:
start_copy,end_copy=start[:],end[:]
if len(start) != len(end):return False
if start.replace('X', '') != end.replace('X', ''):return False
while True:
start_l,end_l=start.find('L'),end.find('L')
if start_l!=-1:
if start_l<end_l:return False
if start_l==len(start)-1 or end_l==len(end)-1:break
start,end=start[start_l+1:],end[end_l+1:]
if start.find('L')==-1:break
else:break
while True:
start_r,end_r=start_copy.find('R'),end_copy.find('R')
if start_r!=-1:
if start_r>end_r:return False
if start_r==len(start_copy)-1 or end_r==len(end_copy)-1:break
start_copy,end_copy=start_copy[start_r+1:],end_copy[end_r+1:]
if start_copy.find('R')==-1:break
else:break
return True
|