0777. Swap Adjacent in LR String
https://leetcode.com/problems/swap-adjacent-in-lr-string
Description
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 ->
XRLXXRRLXExample 2:
**Input:** start = "X", end = "L"
**Output:** falseExample 3:
**Input:** start = "LLR", end = "RRL"
**Output:** falseExample 4:
**Input:** start = "XL", end = "LX"
**Output:** trueExample 5:
**Input:** start = "XLLR", end = "LXLX"
**Output:** falseConstraints:
1 <= start.length <= 104start.length == end.lengthBoth
startandendwill only consist of characters in'L','R', and'X'.
ac
Last updated
Was this helpful?