type
status
date
slug
summary
tags
category
icon
password
题目
On an infinite plane, a robot initially stands at
(0, 0)
and faces north. Note that:- The north direction is the positive direction of the y-axis.
- The south direction is the negative direction of the y-axis.
- The east direction is the positive direction of the x-axis.
- The west direction is the negative direction of the x-axis.
The robot can receive one of three instructions:
"G"
: go straight 1 unit.
"L"
: turn 90 degrees to the left (i.e., anti-clockwise direction).
"R"
: turn 90 degrees to the right (i.e., clockwise direction).
The robot performs the
instructions
given in order, and repeats them forever.Return
true
if and only if there exists a circle in the plane such that the robot never leaves the circle.解题思路
注意审题:这道题目说的是 bounded in circle,即“困在环内”,而不是说“存在环”。
- 执行
instructions
后,回到原点。困在环内。
- 执行
instructions
后,不在原点。面向朝东,困在环内。
- 执行
instructions
后,不在原点。面向朝西,困在环内。
- 执行
instructions
后,不在原点。面向朝南,困在环内。
- 执行
instructions
后,不在原点。面向朝北,不会困在环内。
- 作者:Thomas He
- 链接:https://notion-next-lovat-ten.vercel.app/article/problems/leetcode/1041
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。