java.lang.Object
g0701_0800.s0777_swap_adjacent_in_lr_string.Solution

public class Solution extends Object
777 - Swap Adjacent in LR String.<p>Medium</p> <p>In a string composed of <code>'L'</code>, <code>'R'</code>, and <code>'X'</code> characters, like <code>&quot;RXXLRXRXL&quot;</code>, a move consists of either replacing one occurrence of <code>&quot;XL&quot;</code> with <code>&quot;LX&quot;</code>, or replacing one occurrence of <code>&quot;RX&quot;</code> with <code>&quot;XR&quot;</code>. Given the starting string <code>start</code> and the ending string <code>end</code>, return <code>True</code> if and only if there exists a sequence of moves to transform one string to the other.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> start = &ldquo;RXXLRXRXL&rdquo;, end = &ldquo;XRLXXRRLX&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong></p> <pre><code> We can transform start to end following these steps: RXXLRXRXL -> XRXLRXRXL -> XRLXRXRXL -> XRLXXRRXL -> XRLXXRRLX </code></pre> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> start = &ldquo;X&rdquo;, end = &ldquo;L&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= start.length <= 10<sup>4</sup></code></li> <li><code>start.length == end.length</code></li> <li>Both <code>start</code> and <code>end</code> will only consist of characters in <code>'L'</code>, <code>'R'</code>, and <code>'X'</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • canTransform

      public boolean canTransform(String start, String end)