mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-24 14:28:56 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你一个在 XY 平面上的 <code>width x height</code> 的网格图,<strong>左下角</strong> 的格子为 <code>(0, 0)</code> ,<strong>右上角</strong> 的格子为 <code>(width - 1, height - 1)</code> 。网格图中相邻格子为四个基本方向之一(<code>\"North\"</code>,<code>\"East\"</code>,<code>\"South\"</code> 和 <code>\"West\"</code>)。一个机器人 <strong>初始</strong> 在格子 <code>(0, 0)</code> ,方向为 <code>\"East\"</code> 。</p>\n\n<p>机器人可以根据指令移动指定的 <strong>步数</strong> 。每一步,它可以执行以下操作。</p>\n\n<ol>\n\t<li>沿着当前方向尝试 <strong>往前一步</strong> 。</li>\n\t<li>如果机器人下一步将到达的格子 <strong>超出了边界</strong> ,机器人会 <strong>逆时针</strong> 转 90 度,然后再尝试往前一步。</li>\n</ol>\n\n<p>如果机器人完成了指令要求的移动步数,它将停止移动并等待下一个指令。</p>\n\n<p>请你实现 <code>Robot</code> 类:</p>\n\n<ul>\n\t<li><code>Robot(int width, int height)</code> 初始化一个 <code>width x height</code> 的网格图,机器人初始在 <code>(0, 0)</code> ,方向朝 <code>\"East\"</code> 。</li>\n\t<li><code>void step(int num)</code> 给机器人下达前进 <code>num</code> 步的指令。</li>\n\t<li><code>int[] getPos()</code> 返回机器人当前所处的格子位置,用一个长度为 2 的数组 <code>[x, y]</code> 表示。</li>\n\t<li><code>String getDir()</code> 返回当前机器人的朝向,为 <code>\"North\"</code> ,<code>\"East\"</code> ,<code>\"South\"</code> 或者 <code>\"West\"</code> 。</li>\n</ul>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<p><img alt=\"example-1\" src=\"https://assets.leetcode.com/uploads/2021/10/09/example-1.png\" style=\"width: 498px; height: 268px;\" /></p>\n\n<pre>\n<strong>输入:</strong>\n[\"Robot\", \"step\", \"step\", \"getPos\", \"getDir\", \"step\", \"step\", \"step\", \"getPos\", \"getDir\"]\n[[6, 3], [2], [2], [], [], [2], [1], [4], [], []]\n<strong>输出:</strong>\n[null, null, null, [4, 0], \"East\", null, null, null, [1, 2], \"West\"]\n\n<strong>解释:</strong>\nRobot robot = new Robot(6, 3); // 初始化网格图,机器人在 (0, 0) ,朝东。\nrobot.step(2); // 机器人朝东移动 2 步,到达 (2, 0) ,并朝东。\nrobot.step(2); // 机器人朝东移动 2 步,到达 (4, 0) ,并朝东。\nrobot.getPos(); // 返回 [4, 0]\nrobot.getDir(); // 返回 \"East\"\nrobot.step(2); // 朝东移动 1 步到达 (5, 0) ,并朝东。\n // 下一步继续往东移动将出界,所以逆时针转变方向朝北。\n // 然后,往北移动 1 步到达 (5, 1) ,并朝北。\nrobot.step(1); // 朝北移动 1 步到达 (5, 2) ,并朝 <strong>北</strong> (不是朝西)。\nrobot.step(4); // 下一步继续往北移动将出界,所以逆时针转变方向朝西。\n // 然后,移动 4 步到 (1, 2) ,并朝西。\nrobot.getPos(); // 返回 [1, 2]\nrobot.getDir(); // 返回 \"West\"\n\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>2 <= width, height <= 100</code></li>\n\t<li><code>1 <= num <= 10<sup>5</sup></code></li>\n\t<li><code>step</code> ,<code>getPos</code> 和 <code>getDir</code> <strong>总共 </strong>调用次数不超过 <code>10<sup>4</sup></code> 次。</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 21,
|
||||
"likes": 22,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -149,7 +149,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"5.2K\", \"totalSubmission\": \"23K\", \"totalAcceptedRaw\": 5181, \"totalSubmissionRaw\": 23015, \"acRate\": \"22.5%\"}",
|
||||
"stats": "{\"totalAccepted\": \"5.2K\", \"totalSubmission\": \"23K\", \"totalAcceptedRaw\": 5187, \"totalSubmissionRaw\": 23029, \"acRate\": \"22.5%\"}",
|
||||
"hints": [
|
||||
"The robot only moves along the perimeter of the grid. Can you think if modulus can help you quickly compute which cell it stops at?",
|
||||
"After the robot moves one time, whenever the robot stops at some cell, it will always face a specific direction. i.e., The direction it faces is determined by the cell it stops at.",
|
||||
|
||||
Reference in New Issue
Block a user