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

Function pacificAtlantic0

pacific_atlantic_water_flow_417/solution.go:71–82  ·  view source on GitHub ↗

Initial solution: for each coordinate, see if you can reach both the pacific and the atlantic. Correct solution, but is slow.

(matrix [][]int)

Source from the content-addressed store, hash-verified

69// Initial solution: for each coordinate, see if you can reach
70// both the pacific and the atlantic. Correct solution, but is slow.
71func 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
84func canReachPacific(matrix [][]int, r, c, pr, pc int) bool {
85 if reachedAtlantic(matrix, r, c) {

Callers 1

Test_pacificAtlanticFunction · 0.85

Calls 2

canReachPacificFunction · 0.85
canReachAtlanticFunction · 0.85

Tested by 1

Test_pacificAtlanticFunction · 0.68