#838

Push Dominoes

specialist · 665 · lc medium +30 · verified · 63% accepted · 3,952 likes · top 65%

Description

There are n dominoes standing upright in a row. Some are simultaneously pushed left or right at the start.

Each second, a falling domino pushes its neighbor in the direction it is falling. When a standing domino is pushed from both sides simultaneously, it remains upright due to equal and opposing forces.

A falling domino exerts no additional force on a domino that is already falling or has fallen.

You are given a string dominoes describing the initial state:

- dominoes[i] = 'L' means domino i was pushed left.

- dominoes[i] = 'R' means domino i was pushed right.

- dominoes[i] = '.' means domino i has not been pushed.

Return a string representing the final resting state of the dominoes.

Example 1:

Input: dominoes = "RR.L"
Output: "RR.L"
Explanation: The first domino expends no additional force on the second domino.

Example 2:

Input: dominoes = ".L.R...LR..L.."
Output: "LL.RR.LLRRLL.."

Code

1
2
3