classSolution(object):defpushDominoes(self, dominoes):
symbols =[(i, x)for i, x inenumerate(dominoes)if x !='.']
symbols =[(-1,'L')]+ symbols +[(len(dominoes),'R')]
ans =list(dominoes)for(i, x),(j, y)inzip(symbols, symbols[1:]):if x == y:for k inrange(i +1, j):
ans[k]= x
# because R>L,and this is the solution for the case that like R...L# if L...R,there is no need to change anything,so just ignore.elif x > y:for k inrange(i +1, j):
ans[k]='.LR'[cmp(k - i, j - k)]return"".join(ans)defcmp(a, b):if a == b:return0elif a > b:return1else:return2'''
输入:".L.R...LR..L.."
输出:"LL.RR.LLRRLL.."
输入:"RR.L"
输出:"RR.L"
说明:第一张多米诺骨牌没有给第二张施加额外的力。
'''print(Solution.pushDominoes(Solution,".L.R...LR..L.."))