1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-09 17:31:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2023-12-09 19:57:46 +08:00
parent 9bc4722a45
commit 3770b44d1e
4792 changed files with 10889 additions and 10886 deletions

View File

@@ -7,7 +7,7 @@
"boundTopicId": 33742,
"title": "Queens That Can Attack the King",
"titleSlug": "queens-that-can-attack-the-king",
"content": "<p>On a <strong>0-indexed</strong> <code>8 x 8</code> chessboard, there can be multiple black queens ad one white king.</p>\n\n<p>You are given a 2D integer array <code>queens</code> where <code>queens[i] = [xQueen<sub>i</sub>, yQueen<sub>i</sub>]</code> represents the position of the <code>i<sup>th</sup></code> black queen on the chessboard. You are also given an integer array <code>king</code> of length <code>2</code> where <code>king = [xKing, yKing]</code> represents the position of the white king.</p>\n\n<p>Return <em>the coordinates of the black queens that can directly attack the king</em>. You may return the answer in <strong>any order</strong>.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/12/21/chess1.jpg\" style=\"width: 400px; height: 400px;\" />\n<pre>\n<strong>Input:</strong> queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0]\n<strong>Output:</strong> [[0,1],[1,0],[3,3]]\n<strong>Explanation:</strong> The diagram above shows the three queens that can directly attack the king and the three queens that cannot attack the king (i.e., marked with red dashes).\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/12/21/chess2.jpg\" style=\"width: 400px; height: 400px;\" />\n<pre>\n<strong>Input:</strong> queens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]], king = [3,3]\n<strong>Output:</strong> [[2,2],[3,4],[4,4]]\n<strong>Explanation:</strong> The diagram above shows the three queens that can directly attack the king and the three queens that cannot attack the king (i.e., marked with red dashes).\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= queens.length &lt; 64</code></li>\n\t<li><code>queens[i].length == king.length == 2</code></li>\n\t<li><code>0 &lt;= xQueen<sub>i</sub>, yQueen<sub>i</sub>, xKing, yKing &lt; 8</code></li>\n\t<li>All the given positions are <strong>unique</strong>.</li>\n</ul>\n",
"content": "<p>On a <strong>0-indexed</strong> <code>8 x 8</code> chessboard, there can be multiple black queens and one white king.</p>\n\n<p>You are given a 2D integer array <code>queens</code> where <code>queens[i] = [xQueen<sub>i</sub>, yQueen<sub>i</sub>]</code> represents the position of the <code>i<sup>th</sup></code> black queen on the chessboard. You are also given an integer array <code>king</code> of length <code>2</code> where <code>king = [xKing, yKing]</code> represents the position of the white king.</p>\n\n<p>Return <em>the coordinates of the black queens that can directly attack the king</em>. You may return the answer in <strong>any order</strong>.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/12/21/chess1.jpg\" style=\"width: 400px; height: 400px;\" />\n<pre>\n<strong>Input:</strong> queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0]\n<strong>Output:</strong> [[0,1],[1,0],[3,3]]\n<strong>Explanation:</strong> The diagram above shows the three queens that can directly attack the king and the three queens that cannot attack the king (i.e., marked with red dashes).\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/12/21/chess2.jpg\" style=\"width: 400px; height: 400px;\" />\n<pre>\n<strong>Input:</strong> queens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]], king = [3,3]\n<strong>Output:</strong> [[2,2],[3,4],[4,4]]\n<strong>Explanation:</strong> The diagram above shows the three queens that can directly attack the king and the three queens that cannot attack the king (i.e., marked with red dashes).\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= queens.length &lt; 64</code></li>\n\t<li><code>queens[i].length == king.length == 2</code></li>\n\t<li><code>0 &lt;= xQueen<sub>i</sub>, yQueen<sub>i</sub>, xKing, yKing &lt; 8</code></li>\n\t<li>All the given positions are <strong>unique</strong>.</li>\n</ul>\n",
"translatedTitle": "可以攻击国王的皇后",
"translatedContent": "<p>在一个&nbsp;<strong>8x8</strong>&nbsp;的棋盘上,放置着若干「黑皇后」和一个「白国王」。</p>\n\n<p>给定一个由整数坐标组成的数组&nbsp;<code>queens</code>&nbsp;,表示黑皇后的位置;以及一对坐标&nbsp;<code>king</code> ,表示白国王的位置,返回所有可以攻击国王的皇后的坐标(任意顺序)。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/10/13/untitled-diagram.jpg\" /></p>\n\n<pre>\n<strong>输入:</strong>queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0]\n<strong>输出:</strong>[[0,1],[1,0],[3,3]]\n<strong>解释:</strong> \n[0,1] 的皇后可以攻击到国王,因为他们在同一行上。 \n[1,0] 的皇后可以攻击到国王,因为他们在同一列上。 \n[3,3] 的皇后可以攻击到国王,因为他们在同一条对角线上。 \n[0,4] 的皇后无法攻击到国王,因为她被位于 [0,1] 的皇后挡住了。 \n[4,0] 的皇后无法攻击到国王,因为她被位于 [1,0] 的皇后挡住了。 \n[2,4] 的皇后无法攻击到国王,因为她和国王不在同一行/列/对角线上。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/10/13/untitled-diagram-1.jpg\" /></strong></p>\n\n<pre>\n<strong>输入:</strong>queens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]], king = [3,3]\n<strong>输出:</strong>[[2,2],[3,4],[4,4]]\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/10/13/untitled-diagram-2.jpg\" /></strong></p>\n\n<pre>\n<strong>输入:</strong>queens = [[5,6],[7,7],[2,1],[0,7],[1,6],[5,1],[3,7],[0,3],[4,0],[1,2],[6,3],[5,0],[0,4],[2,2],[1,1],[6,4],[5,4],[0,0],[2,6],[4,5],[5,2],[1,4],[7,5],[2,3],[0,5],[4,2],[1,0],[2,7],[0,1],[4,6],[6,1],[0,6],[4,3],[1,7]], king = [3,4]\n<strong>输出:</strong>[[2,3],[1,4],[1,6],[3,7],[4,3],[5,4],[4,5]]\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= queens.length&nbsp;&lt;= 63</code></li>\n\t<li><code>queens[i].length == 2</code></li>\n\t<li><code>0 &lt;= queens[i][j] &lt;&nbsp;8</code></li>\n\t<li><code>king.length == 2</code></li>\n\t<li><code>0 &lt;= king[0], king[1] &lt; 8</code></li>\n\t<li>一个棋盘格上最多只能放置一枚棋子。</li>\n</ul>\n",
"isPaidOnly": false,
@@ -155,7 +155,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"30.3K\", \"totalSubmission\": \"40.9K\", \"totalAcceptedRaw\": 30279, \"totalSubmissionRaw\": 40921, \"acRate\": \"74.0%\"}",
"stats": "{\"totalAccepted\": \"30.3K\", \"totalSubmission\": \"40.9K\", \"totalAcceptedRaw\": 30282, \"totalSubmissionRaw\": 40924, \"acRate\": \"74.0%\"}",
"hints": [
"Check 8 directions around the King.",
"Find the nearest queen in each direction."