Python Elegant & Short | DFS | 99.21% faster
\n\n\nclass Solution:\n\t"""\n\tTime:   O(n*m)\n\tMemory: O(n*m)\n\t"""\n\n\tMOVES = [(-1, 0), (0, -1), (1, 0), (0, 1)]\n\n\tdef pacificAtlantic(self, heights: 
![image](https://assets.leetcode.com/users/images/6e32f2ac-4bce-4a83-aa85-26bc06457eeb_1661969728.801651.png)\n\n```\nclass Solution:\n\t"""\n\tTime:   O(n*m)\n\tMemory: O(n*m)\n\t"""\n\n\tMOVES = [(-1, 0), (0, -1), (1, 0), (0, 1)]\n\n\tdef pacificAtlantic(self, heights: List[List[int]]) -> Set[Tuple[int, int]]:\n\t\tdef dfs(i: int, j: int, visited: set):\n\t\t\tvisited.add((i, j))\n\t\t\tfor di, dj in self.MOVES:\n\t\t\t\tx, y = i + di, j + dj\n\t\t\t\tif 0 <= x < n and 0 <= y < m and (x, y) not in visited and heights[i][j] <= heights[x][y]:\n\t\t\t\t\tdfs(x, y, visited)\n\n\t\tn, m = len(heights), len(heights[0])\n\n\t\tatl_visited = set()\n\t\tpas_visited = set()\n\n\t\tfor i in range(n):\n\t\t\tdfs(i,     0, pas_visited)\n\t\t\tdfs(i, m - 1, atl_visited)\n\n\t\tfor j in range(m):\n\t\t\tdfs(    0, j, pas_visited)\n\t\t\tdfs(n - 1, j, atl_visited)\n\n\t\treturn atl_visited & pas_visited\n```\n\nIf you like this solution remember to **upvote it** to let me know.
['Depth-First Search', 'Python', 'Python3']