-
Notifications
You must be signed in to change notification settings - Fork 160
/
robot-bounded-in-circle.md
50 lines (37 loc) · 1.55 KB
/
robot-bounded-in-circle.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<p>On an infinite plane, a robot initially stands at <code>(0, 0)</code> and faces north. The robot can receive one of three instructions:</p>
<ul>
<li><code>"G"</code>: go straight 1 unit;</li>
<li><code>"L"</code>: turn 90 degrees to the left;</li>
<li><code>"R"</code>: turn 90 degress to the right.</li>
</ul>
<p>The robot performs the <code>instructions</code> given in order, and repeats them forever.</p>
<p>Return <code>true</code> if and only if there exists a circle in the plane such that the robot never leaves the circle.</p>
<p> </p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong>"GGLLGG"
<strong>Output: </strong>true
<strong>Explanation: </strong>
The robot moves from (0,0) to (0,2), turns 180 degrees, and then returns to (0,0).
When repeating these instructions, the robot remains in the circle of radius 2 centered at the origin.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong>"GG"
<strong>Output: </strong>false
<strong>Explanation: </strong>
The robot moves north indefinitely.
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input: </strong>"GL"
<strong>Output: </strong>true
<strong>Explanation: </strong>
The robot moves from (0, 0) -> (0, 1) -> (-1, 1) -> (-1, 0) -> (0, 0) -> ...
</pre>
<p> </p>
<p><strong>Note:</strong></p>
<ol>
<li><code>1 <= instructions.length <= 100</code></li>
<li><code>instructions[i]</code> is in <code>{'G', 'L', 'R'}</code></li>
</ol>