MCPcopy
hub / github.com/austingebauer/go-leetcode / canReachPacific

Function canReachPacific

pacific_atlantic_water_flow_417/solution.go:84–118  ·  view source on GitHub ↗
(matrix [][]int, r, c, pr, pc int)

Source from the content-addressed store, hash-verified

82}
83
84func 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
120func canReachAtlantic(matrix [][]int, r, c, pr, pc int) bool {
121 if reachedPacific(r, c) {

Callers 1

pacificAtlantic0Function · 0.85

Calls 3

reachedAtlanticFunction · 0.85
reachedPacificFunction · 0.85
waterCanFlowFunction · 0.85

Tested by

no test coverage detected