(matrix [][]int, r, c, pr, pc int)
| 118 | } |
| 119 | |
| 120 | func canReachAtlantic(matrix [][]int, r, c, pr, pc int) bool { |
| 121 | if reachedPacific(r, c) { |
| 122 | return false |
| 123 | } |
| 124 | |
| 125 | if reachedAtlantic(matrix, r, c) { |
| 126 | return true |
| 127 | } |
| 128 | |
| 129 | // go north |
| 130 | if waterCanFlow(matrix, pr, pc, r, c, r-1, c) && |
| 131 | canReachAtlantic(matrix, r-1, c, r, c) { |
| 132 | return true |
| 133 | } |
| 134 | |
| 135 | // go south |
| 136 | if waterCanFlow(matrix, pr, pc, r, c, r+1, c) && |
| 137 | canReachAtlantic(matrix, r+1, c, r, c) { |
| 138 | return true |
| 139 | } |
| 140 | |
| 141 | // go east |
| 142 | if waterCanFlow(matrix, pr, pc, r, c, r, c+1) && |
| 143 | canReachAtlantic(matrix, r, c+1, r, c) { |
| 144 | return true |
| 145 | } |
| 146 | |
| 147 | // go west |
| 148 | if waterCanFlow(matrix, pr, pc, r, c, r, c-1) && |
| 149 | canReachAtlantic(matrix, r, c-1, r, c) { |
| 150 | return true |
| 151 | } |
| 152 | |
| 153 | return false |
| 154 | } |
| 155 | |
| 156 | func reachedAtlantic(matrix [][]int, r, c int) bool { |
| 157 | return r >= len(matrix) || (r > -1 && c >= len(matrix[r])) |
no test coverage detected