★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:山青詠芝(shanqingyongzhi)
➤博客園地址:山青詠芝(https://www.cnblogs.com/strengthen/)
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-djrwdioq-mc.html
➤若是連接不是山青詠芝的博客園地址,則多是爬取做者的文章。
➤原文已修改更新!強烈建議點擊原文地址閱讀!支持做者!支持原創!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html
On an infinite plane, a robot initially stands at (0, 0)
and faces north. The robot can receive one of three instructions:git
"G"
: go straight 1 unit;"L"
: turn 90 degrees to the left;"R"
: turn 90 degress to the right.The robot performs the instructions
given in order, and repeats them forever.github
Return true
if and only if there exists a circle in the plane such that the robot never leaves the circle.微信
Example 1:app
Input: "GGLLGG"
Output: true Explanation: 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.
Example 2:spa
Input: "GG"
Output: false Explanation: The robot moves north indefinetely.
Example 3:code
Input: "GL"
Output: true Explanation: The robot moves from (0, 0) -> (0, 1) -> (-1, 1) -> (-1, 0) -> (0, 0) -> ...
Note:orm
1 <= instructions.length <= 100
instructions[i]
is in {'G', 'L', 'R'}
在無限的平面上,機器人最初位於 (0, 0)
處,面朝北方。機器人能夠接受下列三條指令之一:htm
"G"
:直走 1 個單位"L"
:左轉 90 度"R"
:右轉 90 度機器人按順序執行指令 instructions
,並一直重複它們。blog
只有在平面中存在環使得機器人永遠沒法離開時,返回 true
。不然,返回 false
。
示例 1:
輸入:"GGLLGG" 輸出:true 解釋: 機器人從 (0,0) 移動到 (0,2),轉 180 度,而後回到 (0,0)。 重複這些指令,機器人將保持在以原點爲中心,2 爲半徑的環中進行移動。
示例 2:
輸入:"GG" 輸出:false 解釋: 機器人無限向北移動。
示例 3:
輸入:"GL" 輸出:true 解釋: 機器人按 (0, 0) -> (0, 1) -> (-1, 1) -> (-1, 0) -> (0, 0) -> ... 進行移動。
提示:
1 <= instructions.length <= 100
instructions[i]
在 {'G', 'L', 'R'}
中