[Java/C++] Check 8 directions from King, Clean code, 0 ms beat 100%
Java\njava\npublic class Solution {\n    public List<List<Integer>> queensAttacktheKing(int[][] queens, int[] king) {\n        List<List<Integer>> result = new 
**Java**\n```java\npublic class Solution {\n    public List<List<Integer>> queensAttacktheKing(int[][] queens, int[] king) {\n        List<List<Integer>> result = new ArrayList<>();\n        boolean[][] seen = new boolean[8][8];\n        for (int[] queen : queens) seen[queen[0]][queen[1]] = true;\n\n        for (int dr = -1; dr <= 1; dr++) { // find the nearest queen can attack king by 8 directions\n            for (int dc = -1; dc <= 1; dc++) {\n                if (dr == 0 && dc == 0) continue; // exclude center\n                List<Integer> queen = findNearestQueenCanAttackKing(seen, king, dr, dc);\n                if (queen != null) result.add(queen);\n            }\n        }\n        return result;\n    }\n\n    private List<Integer> findNearestQueenCanAttackKing(boolean[][] seen, int[] king, int dr, int dc) {\n        int r = king[0] + dr, c = king[1] + dc;\n        while (r >= 0 && c >= 0 && r < 8 && c < 8) {\n            if (seen[r][c]) return Arrays.asList(r, c);\n            r += dr;\n            c += dc;\n        }\n        return null;\n    }\n}\n```\n\n**C++**\n```C++\nclass Solution {\npublic:\n    vector<vector<int>> queensAttacktheKing(vector<vector<int>>& queens, vector<int>& king) {\n        vector<vector<int>> result;\n        bool seen[8][8] = {};\n        for (vector<int> queen : queens) seen[queen[0]][queen[1]] = true;\n\n        for (int dr = -1; dr <= 1; dr++) { // find the nearest queen can attack king by 8 directions\n            for (int dc = -1; dc <= 1; dc++) {\n                if (dr == 0 && dc == 0) continue; // exclude center\n                vector<int> queen = findNearestQueenCanAttackKing(seen, king, dr, dc);\n                if (queen.size() > 0) result.push_back(queen);\n            }\n        }\n        return result;\n    }\n    \n    vector<int> findNearestQueenCanAttackKing(bool seen[8][8], vector<int>& king, int dr, int dc) {\n        int r = king[0] + dr, c = king[1] + dc;\n        while (r >= 0 && c >= 0 && r < 8 && c < 8) {\n            if (seen[r][c]) return vector<int>{r, c};\n            r += dr;\n            c += dc;\n        }\n        return vector<int>{};\n    }\n};\n```\n\n**Complexity**\n- Time: O(N + 8\\*8), N <= 63\n- Splace: O(64), for seen array
[]