class Solution {
public List<List<Integer>> queensAttacktheKing(int[][] queens, int[] king) {
//对于queen,直接完全遍历一次建立Hash
int[][] dir = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
int[][] isq = new int[8][8];
for(int i = 0;i < 8;i++){
for(int j = 0;j < 8;j++){
isq[i][j] = 0;
}
}
for(int[]q : queens){
isq[q[0]][q[1]] = 1;
}
List<List<Integer>> ans = new ArrayList<List<Integer>>();
for(int i = 0;i < 8;i++){//遍历八个方向
List<Integer> tmp = new ArrayList<>();
for(int newx = dir[i][0] + king[0],newy = dir[i][1] + king[1]; ;newx += dir[i][0],newy += dir[i][1]){//对于一个方向,不断延伸
if(newx < 0 || newy < 0 || newx >= 8 || newy >= 8){
break;
}
if(isq[newx][newy] == 1){
tmp.add(newx);
tmp.add(newy);
ans.add(tmp);
break;
}
}
}
return ans;
}
}