We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9870992 commit 1733a91Copy full SHA for 1733a91
go/flood_fill.go
@@ -3,21 +3,16 @@ package main
3
4
func floodFill(image [][]int, sr int, sc int, color int) [][]int {
5
originalColor := image[sr][sc]
6
-
7
if originalColor == color {
8
return image
9
}
10
image[sr][sc] = color
11
12
- directions := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}
13
- for _, d := range directions {
14
- nSr, nSc := sr+d[0], sc+d[1]
15
- if 0 <= nSr && nSr < len(image) &&
16
- 0 <= nSc && nSc < len(image[0]) &&
17
- image[nSr][nSc] == originalColor {
18
- image = floodFill(image, nSr, nSc, color)
+ directions := [][]int{{0, 1}, {0, -1}, {1, 0}, {-1, 0}}
+ for _, direction := range directions {
+ newSr, newSc := sr+direction[0], sc+direction[1]
+ if 0 <= newSr && newSr < len(image) && 0 <= newSc && newSc < len(image[0]) && image[newSr][newSc] == originalColor {
+ floodFill(image, newSr, newSc, color)
19
20
21
22
23
0 commit comments