Simple java dfs solution
Build two sets for Pacific and Atlantic. The result is the intersection of them.\n\n private int[][] direction = new int[][]{{1, 0},{0, 1},{-1, 0},{0, -1}};\n  
Build two sets for Pacific and Atlantic. The result is the intersection of them.\n```\n private int[][] direction = new int[][]{{1, 0},{0, 1},{-1, 0},{0, -1}};\n    public List<int[]> pacificAtlantic(int[][] matrix) {\n        List<int[]> result = new ArrayList<>();\n        if (matrix.length == 0) return result;\n        Set<Integer> pacific = new HashSet<>();\n        Set<Integer> atlantic = new HashSet<>();\n        for (int i = 0; i < matrix[0].length; i++) {\n            dfs(matrix, 0, i, pacific);\n            dfs(matrix, matrix.length - 1, i, atlantic);\n        }\n        for (int i = 0; i < matrix.length; i++) {\n            dfs(matrix, i, 0, pacific);\n            dfs(matrix, i, matrix[0].length - 1, atlantic);\n        }\n        \n        for (int i: pacific) {\n            if (atlantic.contains(i)) {\n                result.add(decode(i, matrix));\n            }\n        }\n        return result;\n    }\n    \n    private void dfs(int[][] matrix, int i, int j, Set<Integer> result) {\n        if (!result.add(encode(i, j, matrix))) return;\n        for (int[] dir: direction) {\n            int x = dir[0] + i;\n            int y = dir[1] + j;\n            if (x >= 0 && x < matrix.length && y >= 0 && y < matrix[0].length && matrix[x][y] >= matrix[i][j]) {\n                dfs(matrix, x, y, result);\n            }\n        }\n    }\n    \n    private int[] decode(int i, int[][] matrix) {\n        return new int[]{i / matrix[0].length, i % matrix[0].length};\n    }\n    \n    private int encode(int i, int j, int[][] matrix) {\n        return i * matrix[0].length + j;\n    }\n```
['Java']