← 返回 google 的题目列表Move Chess Pieces to Match Target (R moves right, L moves left)
类型:online_judge
Given two equal-length strings start and target representing a 1D board:
'R': a piece that can only move right
'L': a piece that can only move left
'_': empty cell
A move swaps a piece with an adjacent empty cell in its allowed direction (e.g., R_ -> _R, _L -> L_).
Determine whether start can be transformed into target using any number of moves.
Input
Line 1: start
Line 2: target
Output
Print true or false
Constraints
1 <= n = len(start) = len(target) <= 2*10^5
Strings contain only 'R','L','_'
Examples
start="_L__R__R_", target="L______RR" -> true
start="R_L_", target="__LR" -> false
Example
Input
_L__R__R_
L______RR
Output
true