This website contains ALL LeetCode **Premium** problems for
**FREE!!**.

All leaked interview problems are collected from Internet.

All leaked interview problems are collected from Internet.

Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to **the original place**.

The move sequence is represented by a string. And each move is represent by a character. The valid robot moves are `R`

(Right), `L`

(Left), `U`

(Up) and `D`

(down). The output should be true or false representing whether the robot makes a circle.

**Example 1:**

Input:"UD"Output:true

**Example 2:**

Input:"LL"Output:false

b'

\n\n

\n#### Approach #1: Simulation [Accepted]

\n

\n

'
\n

**Intuition**

We can simulate the position of the robot after each command.

\n**Algorithm**

Initially, the robot is at `(x, y) = (0, 0)`

. If the move is `\'U\'`

, the robot goes to `(x, y-1)`

; if the move is `\'R\'`

, the robot goes to `(x, y) = (x+1, y)`

, and so on.

**Complexity Analysis**

- \n
- \n
Time Complexity: , where is the length of

\n`moves`

. We iterate through the string. \n - \n
Space Complexity: . In Java, our character array is .

\n \n

\n

Analysis written by: @awice.

\n