mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
43 lines
1.9 KiB
HTML
43 lines
1.9 KiB
HTML
<p>力扣团队买了一个可编程机器人,机器人初始位置在原点<code>(0, 0)</code>。小伙伴事先给机器人输入一串指令<code>command</code>,机器人就会<strong>无限循环</strong>这条指令的步骤进行移动。指令有两种:</p>
|
||
|
||
<ol>
|
||
<li><code>U</code>: 向<code>y</code>轴正方向移动一格</li>
|
||
<li><code>R</code>: 向<code>x</code>轴正方向移动一格。</li>
|
||
</ol>
|
||
|
||
<p>不幸的是,在 xy 平面上还有一些障碍物,他们的坐标用<code>obstacles</code>表示。机器人一旦碰到障碍物就会被<strong>损毁</strong>。</p>
|
||
|
||
<p>给定终点坐标<code>(x, y)</code>,返回机器人能否<strong>完好</strong>地到达终点。如果能,返回<code>true</code>;否则返回<code>false</code>。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>command = "URR", obstacles = [], x = 3, y = 2
|
||
<strong>输出:</strong>true
|
||
<strong>解释:</strong>U(0, 1) -> R(1, 1) -> R(2, 1) -> U(2, 2) -> R(3, 2)。</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>command = "URR", obstacles = [[2, 2]], x = 3, y = 2
|
||
<strong>输出:</strong>false
|
||
<strong>解释:</strong>机器人在到达终点前会碰到(2, 2)的障碍物。</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>command = "URR", obstacles = [[4, 2]], x = 3, y = 2
|
||
<strong>输出:</strong>true
|
||
<strong>解释:</strong>到达终点后,再碰到障碍物也不影响返回结果。</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>限制:</strong></p>
|
||
|
||
<ol>
|
||
<li><code>2 <= command的长度 <= 1000</code></li>
|
||
<li><code>command</code>由<code>U,R</code>构成,且至少有一个<code>U</code>,至少有一个<code>R</code></li>
|
||
<li><code>0 <= x <= 1e9, 0 <= y <= 1e9</code></li>
|
||
<li><code>0 <= obstacles的长度 <= 1000</code></li>
|
||
<li><code>obstacles[i]</code>不为原点或者终点</li>
|
||
</ol>
|