java.lang.Object
g0701_0800.s0777_swap_adjacent_in_lr_string.Solution

public class Solution extends java.lang.Object
777 - Swap Adjacent in LR String.

Medium

In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform one string to the other.

Example 1:

Input: start = “RXXLRXRXL”, end = “XRLXXRRLX”

Output: true

Explanation:

 We can transform start to end following these steps:
 RXXLRXRXL ->
 XRXLRXRXL ->
 XRLXRXRXL ->
 XRLXXRRXL ->
 XRLXXRRLX 

Example 2:

Input: start = “X”, end = “L”

Output: false

Constraints:

  • 1 <= start.length <= 104
  • start.length == end.length
  • Both start and end will only consist of characters in 'L', 'R', and 'X'.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    canTransform(java.lang.String start, java.lang.String end)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • canTransform

      public boolean canTransform(java.lang.String start, java.lang.String end)