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:
Example 2:
Code