A robot starts at (0, 0) on a 2D plane. Given a string `moves` of its moves, where each move is "R" (right), "L" (left), "U" (up) or "D" (down), return true if the robot ends back at (0, 0) after all the moves, and false otherwise. Each move has the same length and the robot's facing does not matter.
A robot starts at (0, 0) on a 2D plane. Given a string moves of its moves, where each move is "R" (right), "L" (left), "U" (up) or "D" (down), return true if the robot ends back at (0, 0) after all the moves, and false otherwise. Each move has the same length and the robot's facing does not matter.
Example 1:
Input: {"moves":"UD"}
Output: true
Constraints:
1 <= moves.length <= 2 * 10^4
moves only contains the characters 'U', 'D', 'L' and 'R'.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"moves":"UD"}
The robot stands on the origin (0, 0). Every U must be cancelled by a D and every L by an R for it to come home, so track x and y while replaying the 2 moves.