Robot Return to Origin — Simulation & Parsing
Given a string of single-letter moves on an open grid, decide whether the robot ends the sequence back at its starting point.
Simulation & Parsing · Easy
The problem
A robot starts on an open grid. You get a string of moves: U is one step up, D one step down, L one step left and R one step right. Decide whether the robot ends up where it started after doing every move in order.
The story
A warehouse robot starts at a marked spot on an open floor. Its route is a string of 1 to 12 moves: U steps one square up, D one down, L one left and R one right. After the robot has done every move in order, decide whether it is standing on the spot where it started.
What to return
- Return true if the robot ends on its starting square after all moves, otherwise false.
Constraints
- 1 <= moves.length <= 12
- moves uses only the letters U, D, L and R
Example
- Input
moves = "UD"- Output
true