657 Judge Route Circle
657. Judge Route Circle
1. Question
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 areR
(Right),L
(Left),U
(Up) andD
(down). The output should be true or false representing whether the robot makes a circle.
Example 1:
Example 2:
2. Implementation
(1) Intuition
(2) HashMap
3. Time & Space Complexity
Intuition: 时间复杂度O(n), 空间复杂度O(1)
HashMap: 时间复杂度O(n), 空间复杂度O(n)
Last updated