1222. Queens That Can Attack the King Medium
1/**
2 * [1222] Queens That Can Attack the King
3 *
4 * On an 8x8 chessboard, there can be multiple Black Queens and one White King.
5 *
6 * Given an array of integer coordinates queens that represents the positions of the Black Queens, and a pair of coordinates king that represent the position of the White King, return the coordinates of all the queens (in any order) that can attack the King.
7 *
8 * Example 1:
9 *
10 * <img alt="" src="https://assets.leetcode.com/uploads/2019/10/01/untitled-diagram.jpg" style="width: 321px; height: 321px;" />
11 *
12 *
13 * Input: queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0]
14 * Output: [[0,1],[1,0],[3,3]]
15 * Explanation:
16 * The queen at [0,1] can attack the king cause they're in the same row.
17 * The queen at [1,0] can attack the king cause they're in the same column.
18 * The queen at [3,3] can attack the king cause they're in the same diagnal.
19 * The queen at [0,4] can't attack the king cause it's blocked by the queen at [0,1].
20 * The queen at [4,0] can't attack the king cause it's blocked by the queen at [1,0].
21 * The queen at [2,4] can't attack the king cause it's not in the same row/column/diagnal as the king.
22 *
23 *
24 * Example 2:
25 *
26 * <img alt="" src="https://assets.leetcode.com/uploads/2019/10/01/untitled-diagram-1.jpg" style="width: 321px; height: 321px;" />
27 *
28 *
29 * Input: queens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]], king = [3,3]
30 * Output: [[2,2],[3,4],[4,4]]
31 *
32 *
33 * Example 3:
34 *
35 * <img alt="" src="https://assets.leetcode.com/uploads/2019/10/01/untitled-diagram-2.jpg" style="width: 321px; height: 321px;" />
36 *
37 *
38 * Input: 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]
39 * Output: [[2,3],[1,4],[1,6],[3,7],[4,3],[5,4],[4,5]]
40 *
41 * Constraints:
42 *
43 * 1 <= queens.length <= 63
44 * queens[i].length == 2
45 * 0 <= queens[i][j] < 8
46 * king.length == 2
47 * 0 <= king[0], king[1] < 8
48 * At most one piece is allowed in a cell.
49 *
50 */
51pub struct Solution {}
52
53// problem: https://leetcode.com/problems/queens-that-can-attack-the-king/
54// discuss: https://leetcode.com/problems/queens-that-can-attack-the-king/discuss/?currentPage=1&orderBy=most_votes&query=
55
56// submission codes start here
57
58impl Solution {
59 pub fn queens_attackthe_king(queens: Vec<Vec<i32>>, king: Vec<i32>) -> Vec<Vec<i32>> {
60 vec![]
61 }
62}
63
64// submission codes end
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
71 fn test_1222() {
72 }
73}
74
Back
© 2025 bowen.ge All Rights Reserved.