(matrix [][]int, r, c, pr, pc int)
| 82 | } |
| 83 | |
| 84 | func canReachPacific(matrix [][]int, r, c, pr, pc int) bool { |
| 85 | if reachedAtlantic(matrix, r, c) { |
| 86 | return false |
| 87 | } |
| 88 | |
| 89 | if reachedPacific(r, c) { |
| 90 | return true |
| 91 | } |
| 92 | |
| 93 | // go north |
| 94 | if waterCanFlow(matrix, pr, pc, r, c, r-1, c) && |
| 95 | canReachPacific(matrix, r-1, c, r, c) { |
| 96 | return true |
| 97 | } |
| 98 | |
| 99 | // go south |
| 100 | if waterCanFlow(matrix, pr, pc, r, c, r+1, c) && |
| 101 | canReachPacific(matrix, r+1, c, r, c) { |
| 102 | return true |
| 103 | } |
| 104 | |
| 105 | // go east |
| 106 | if waterCanFlow(matrix, pr, pc, r, c, r, c+1) && |
| 107 | canReachPacific(matrix, r, c+1, r, c) { |
| 108 | return true |
| 109 | } |
| 110 | |
| 111 | // go west |
| 112 | if waterCanFlow(matrix, pr, pc, r, c, r, c-1) && |
| 113 | canReachPacific(matrix, r, c-1, r, c) { |
| 114 | return true |
| 115 | } |
| 116 | |
| 117 | return false |
| 118 | } |
| 119 | |
| 120 | func canReachAtlantic(matrix [][]int, r, c, pr, pc int) bool { |
| 121 | if reachedPacific(r, c) { |
no test coverage detected