在这里插class Solution {
public:
vector<vector<int>> queensAttacktheKing(vector<vector<int>>& queens, vector<int>& king) {
set<vector<int>> s(queens.begin(), queens.end());
vector<vector<int>> res;
for (auto& dir : dirs) {
vector<int> pos = king;
while (true) {
pos[0] += dir[0];
pos[1] += dir[1];
if (pos[0] < 0 || pos[0] >= 8 || pos[1] < 0 || pos[1] >= 8)
break;
if (s.count(pos)) {
res.push_back(pos);
break;
}
}
}
return res;
}
private:
vector<vector<int>> dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
};
入代码片
06-02
06-02
01-03
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交