Skip to content

Commit

Permalink
finish flood fill
Browse files Browse the repository at this point in the history
  • Loading branch information
myshkins committed Jan 4, 2025
1 parent 66ebf66 commit ef53eca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
9 changes: 4 additions & 5 deletions go/easy/binary_search.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package main

import "fmt"

func search(nums []int, target int) int {
low, hi := 0, len(nums)-1
Expand All @@ -21,7 +20,7 @@ func search(nums []int, target int) int {
return -1
}

func main() {
nums := []int{2, 5}
fmt.Println(search(nums, 5))
}
// func main() {
// nums := []int{2, 5}
// fmt.Println(search(nums, 5))
// }
19 changes: 14 additions & 5 deletions go/easy/flood_fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ func scanAndChange(row, col int) {
gImage[row][col] = targetColor

adjacents := [][]int{
{row+1, col},
{row, col+1},
{row-1, col},
{row, col-1},
{row-1, col}, // top
{row, col+1}, // right
{row+1, col}, // bottom
{row, col-1}, // left
}

for _, cell := range adjacents {
// check that the cell is not outside image boundary
if cell[0] > len(gImage)-1 || cell[0] < 0 {
continue
}
if cell[1] > len(cell)-1 || cell[1] < 0 {
if cell[1] > len(gImage[0])-1 || cell[1] < 0 {
continue
}

Expand Down Expand Up @@ -48,3 +48,12 @@ func floodFill(image [][]int, sr int, sc int, color int) [][]int {
scanAndChange(sr, sc)
return image
}

// func main() {
// input := [][]int{
// {1,1,1},
// {1,1,0},
// {1,0,1},
// }
// fmt.Println(floodFill(input, 1, 1, 2))
// }
1 change: 0 additions & 1 deletion go/easy/valid_palindrome.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"regexp"
"strings"
)
Expand Down

0 comments on commit ef53eca

Please sign in to comment.