Initial solution: for each coordinate, see if you can reach both the pacific and the atlantic. Correct solution, but is slow.
(matrix [][]int)
| 69 | // Initial solution: for each coordinate, see if you can reach |
| 70 | // both the pacific and the atlantic. Correct solution, but is slow. |
| 71 | func pacificAtlantic0(matrix [][]int) [][]int { |
| 72 | coordinates := make([][]int, 0) |
| 73 | for r := 0; r < len(matrix); r++ { |
| 74 | for c := 0; c < len(matrix[r]); c++ { |
| 75 | if canReachPacific(matrix, r, c, r, c) && canReachAtlantic(matrix, r, c, r, c) { |
| 76 | coordinates = append(coordinates, []int{r, c}) |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return coordinates |
| 82 | } |
| 83 | |
| 84 | func canReachPacific(matrix [][]int, r, c, pr, pc int) bool { |
| 85 | if reachedAtlantic(matrix, r, c) { |