Easy understand DFS solution beat 97%
\n\nPython\ndef pacificAtlantic(self, matrix: List[List[int]]) -> List[List[int]]:\n        if not matrix or not matrix[0]:return []\n        m, n = len(matrix)
![image](https://assets.leetcode.com/users/jefferyzzy/image_1584588025.png)\n\n```Python\ndef pacificAtlantic(self, matrix: List[List[int]]) -> List[List[int]]:\n        if not matrix or not matrix[0]:return []\n        m, n = len(matrix),len(matrix[0])\n        p_visited = set()\n        a_visited = set()\n        directions = [(-1, 0), (1, 0), (0, 1), (0, -1)]\n        def dfs(visited, x,y):\n            visited.add((x,y))\n            for dx, dy in directions:\n                new_x, new_y = x+dx, y+dy\n                if 0<=new_x<m and 0<=new_y<n and (new_x,new_y) not in visited and matrix[new_x][new_y]>=matrix[x][y]:\n                    dfs(visited, new_x,new_y)\n        #iterate from left border and right border\n        for i in range(m):\n            dfs(p_visited,i,0)\n            dfs(a_visited,i,n-1)\n        #iterate from up border and bottom border\n        for j in range(n):\n            dfs(p_visited,0,j)\n            dfs(a_visited,m-1,j)\n        #The intersections of two sets are coordinates where water can flow to both P and A\n        return list(p_visited.intersection(a_visited))\n```
['Ordered Set', 'Python', 'Python3']