mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-25 06:48:57 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你一个下标从 <strong>0</strong> 开始的二维整数数组 <code>grid</code> ,它的大小为 <code>m x n</code> ,表示一个商店中物品的分布图。数组中的整数含义为:</p>\n\n<ul>\n\t<li><code>0</code> 表示无法穿越的一堵墙。</li>\n\t<li><code>1</code> 表示可以自由通过的一个空格子。</li>\n\t<li>所有其他正整数表示该格子内的一样物品的价格。你可以自由经过这些格子。</li>\n</ul>\n\n<p>从一个格子走到上下左右相邻格子花费 <code>1</code> 步。</p>\n\n<p>同时给你一个整数数组 <code>pricing</code> 和 <code>start</code> ,其中 <code>pricing = [low, high]</code> 且 <code>start = [row, col]</code> ,表示你开始位置为 <code>(row, col)</code> ,同时你只对物品价格在<strong> 闭区间</strong> <code>[low, high]</code> 之内的物品感兴趣。同时给你一个整数 <code>k</code> 。</p>\n\n<p>你想知道给定范围 <strong>内</strong> 且 <strong>排名最高</strong> 的 <code>k</code> 件物品的 <strong>位置</strong> 。排名按照优先级从高到低的以下规则制定:</p>\n\n<ol>\n\t<li>距离:定义为从 <code>start</code> 到一件物品的最短路径需要的步数(<strong>较近</strong> 距离的排名更高)。</li>\n\t<li>价格:<strong>较低</strong> 价格的物品有更高优先级,但只考虑在给定范围之内的价格。</li>\n\t<li>行坐标:<strong>较小</strong> 行坐标的有更高优先级。</li>\n\t<li>列坐标:<strong>较小</strong> 列坐标的有更高优先级。</li>\n</ol>\n\n<p>请你返回给定价格内排名最高的 <code>k</code> 件物品的坐标,将它们按照排名排序后返回。如果给定价格内少于 <code>k</code> 件物品,那么请将它们的坐标 <strong>全部</strong> 返回。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/12/16/example1drawio.png\" style=\"width: 200px; height: 151px;\"></p>\n\n<pre><b>输入:</b>grid = [[1,2,0,1],[1,3,0,1],[0,2,5,1]], pricing = [2,5], start = [0,0], k = 3\n<b>输出:</b>[[0,1],[1,1],[2,1]]\n<b>解释:</b>起点为 (0,0) 。\n价格范围为 [2,5] ,我们可以选择的物品坐标为 (0,1),(1,1),(2,1) 和 (2,2) 。\n这些物品的排名为:\n- (0,1) 距离为 1\n- (1,1) 距离为 2\n- (2,1) 距离为 3\n- (2,2) 距离为 4\n所以,给定价格范围内排名最高的 3 件物品的坐标为 (0,1),(1,1) 和 (2,1) 。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/12/16/example2drawio1.png\" style=\"width: 200px; height: 151px;\"></p>\n\n<pre><b>输入:</b>grid = [[1,2,0,1],[1,3,3,1],[0,2,5,1]], pricing = [2,3], start = [2,3], k = 2\n<b>输出:</b>[[2,1],[1,2]]\n<b>解释:</b>起点为 (2,3) 。\n价格范围为 [2,3] ,我们可以选择的物品坐标为 (0,1),(1,1),(1,2) 和 (2,1) 。\n这些物品的排名为: \n- (2,1) 距离为 2 ,价格为 2\n- (1,2) 距离为 2 ,价格为 3\n- (1,1) 距离为 3\n- (0,1) 距离为 4\n所以,给定价格范围内排名最高的 2 件物品的坐标为 (2,1) 和 (1,2) 。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/12/30/example3.png\" style=\"width: 149px; height: 150px;\"></p>\n\n<pre><b>输入:</b>grid = [[1,1,1],[0,0,1],[2,3,4]], pricing = [2,3], start = [0,0], k = 3\n<b>输出:</b>[[2,1],[2,0]]\n<b>解释:</b>起点为 (0,0) 。\n价格范围为 [2,3] ,我们可以选择的物品坐标为 (2,0) 和 (2,1) 。\n这些物品的排名为:\n- (2,1) 距离为 5\n- (2,0) 距离为 6\n所以,给定价格范围内排名最高的 2 件物品的坐标为 (2,1) 和 (2,0) 。\n注意,k = 3 但给定价格范围内只有 2 件物品。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>m == grid.length</code></li>\n\t<li><code>n == grid[i].length</code></li>\n\t<li><code>1 <= m, n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= m * n <= 10<sup>5</sup></code></li>\n\t<li><code>0 <= grid[i][j] <= 10<sup>5</sup></code></li>\n\t<li><code>pricing.length == 2</code></li>\n\t<li><code>2 <= low <= high <= 10<sup>5</sup></code></li>\n\t<li><code>start.length == 2</code></li>\n\t<li><code>0 <= row <= m - 1</code></li>\n\t<li><code>0 <= col <= n - 1</code></li>\n\t<li><code>grid[row][col] > 0</code></li>\n\t<li><code>1 <= k <= m * n</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 16,
|
||||
"likes": 18,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -161,7 +161,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"3K\", \"totalSubmission\": \"7.8K\", \"totalAcceptedRaw\": 3003, \"totalSubmissionRaw\": 7817, \"acRate\": \"38.4%\"}",
|
||||
"stats": "{\"totalAccepted\": \"3.1K\", \"totalSubmission\": \"8.1K\", \"totalAcceptedRaw\": 3116, \"totalSubmissionRaw\": 8077, \"acRate\": \"38.6%\"}",
|
||||
"hints": [
|
||||
"Could you determine the rank of every item efficiently?",
|
||||
"We can perform a breadth-first search from the starting position and know the length of the shortest path from start to every item.",
|
||||
|
||||
Reference in New Issue
Block a user