-
Notifications
You must be signed in to change notification settings - Fork 481
/
Copy path1222.cpp
28 lines (28 loc) · 790 Bytes
/
1222.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution
{
public:
vector<vector<int>> queensAttacktheKing(vector<vector<int>>& queens, vector<int>& king)
{
int g[8][8];
memset(g, 0, sizeof g);
vector<vector<int>> res;
for (auto& it : queens) g[it[0]][it[1]] = 1;
for (int i = -1; i <= 1; i++)
{
for (int j = -1; j <= 1; j++)
{
for (int k = 1; k < 8; k++)
{
int x = king[0] + k*i, y = king[1] + k*j;
if (x >= 0 and y >= 0 and
x < 8 and y < 8 and g[x][y] == 1)
{
res.push_back({x, y});
break;
}
}
}
}
return res;
}
};