MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / explore

Function explore

pacific_atlantic_water_flow_417/solution.go:52–67  ·  view source on GitHub ↗
(matrix [][]int, visited *[][]bool, prev, r, c int)

Source from the content-addressed store, hash-verified

50}
51
52func explore(matrix [][]int, visited *[][]bool, prev, r, c int) {
53 v := *visited
54
55 // if we can't travel further, then return
56 if r < 0 || c < 0 ||
57 r >= len(matrix) || c >= len(matrix[0]) ||
58 v[r][c] || matrix[r][c] < prev {
59 return
60 }
61
62 v[r][c] = true
63 explore(matrix, visited, matrix[r][c], r-1, c) // north
64 explore(matrix, visited, matrix[r][c], r+1, c) // south
65 explore(matrix, visited, matrix[r][c], r, c+1) // east
66 explore(matrix, visited, matrix[r][c], r, c-1) // west
67}
68
69// Initial solution: for each coordinate, see if you can reach
70// both the pacific and the atlantic. Correct solution, but is slow.

Callers 1

pacificAtlanticFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected