<p>There are <code>n</code> dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to the left or to the right.</p>

<p>After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right.</p>

<p>When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces.</p>

<p>For the purposes of this question, we will consider that a falling domino expends no additional force to a falling or already fallen domino.</p>

<p>You are given a string <code>dominoes</code> representing the initial state where:</p>

<ul>
	<li><code>dominoes[i] = &#39;L&#39;</code>, if the <code>i<sup>th</sup></code> domino has been pushed to the left,</li>
	<li><code>dominoes[i] = &#39;R&#39;</code>, if the <code>i<sup>th</sup></code> domino has been pushed to the right, and</li>
	<li><code>dominoes[i] = &#39;.&#39;</code>, if the <code>i<sup>th</sup></code> domino has not been pushed.</li>
</ul>

<p>Return <em>a string representing the final state</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> dominoes = &quot;RR.L&quot;
<strong>Output:</strong> &quot;RR.L&quot;
<strong>Explanation:</strong> The first domino expends no additional force on the second domino.
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/05/18/domino.png" style="height: 196px; width: 512px;" />
<pre>
<strong>Input:</strong> dominoes = &quot;.L.R...LR..L..&quot;
<strong>Output:</strong> &quot;LL.RR.LLRRLL..&quot;
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>n == dominoes.length</code></li>
	<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
	<li><code>dominoes[i]</code> is either <code>&#39;L&#39;</code>, <code>&#39;R&#39;</code>, or <code>&#39;.&#39;</code>.</li>
</ul>

class Solution:
    def pushDominoes(self, dominoes: str) -> str:
        # Initialize a temporary variable to store the previous state of the dominoes
        temp = ''
        
        # Continue processing until no changes occur between iterations
        while dominoes != temp:
            # Store the current state of dominoes in temp
            temp = dominoes
            
            # Step 1: Replace 'R.L' with a dummy string 'xxx' to handle the balanced state
            dominoes = dominoes.replace('R.L', 'xxx')
            
            # Step 2: Replace 'R.' with 'RR' to simulate the rightward push
            dominoes = dominoes.replace('R.', 'RR')
            
            # Step 2: Replace '.L' with 'LL' to simulate the leftward push
            dominoes = dominoes.replace('.L', 'LL')
        
        # Step 3: Replace the dummy string 'xxx' back to 'R.L' to restore the balanced state
        return dominoes.replace('xxx', 'R.L')

# Explanation of the solution approach:
# 1. The algorithm uses a loop to repeatedly update the state of the dominoes until no further changes occur.
# 2. To handle the special case where a domino is pushed from both sides ('R.L'), we temporarily replace it with 'xxx'.
# 3. The replacements 'R.' to 'RR' and '.L' to 'LL' simulate the dominoes falling to the right and left, respectively.
# 4. The loop continues until the state of the dominoes stabilizes, meaning no further changes are made.
# 5. Finally, the dummy string 'xxx' is replaced back with 'R.L' to reflect the balanced state where forces cancel each other out.
17900