diff --git a/dp/dp_test.go b/dp/dp_test.go new file mode 100644 index 0000000..fbd1a17 --- /dev/null +++ b/dp/dp_test.go @@ -0,0 +1,53 @@ +package dp + +import ( + "fmt" + "testing" +) + +func countThePath(grid [][]int) int { + if len(grid) == 0 || len(grid[0]) == 0 { + return 0 + } + opt := make([][]int, len(grid)) + for i := 0; i < len(grid); i++ { + opt[i] = make([]int, len(grid[i])) + } + for i := len(grid) - 1; i >= 0; i-- { + for j := len(grid[i]) - 1; j >= 0; j-- { + if i+1 >= len(grid) { + opt[i][j] = 1 + continue + } + if j+1 >= len(grid[i]) { + opt[i][j] = 1 + continue + } + if grid[i+1][j] == 0 { + opt[i][j] += opt[i+1][j] + } + if grid[i][j+1] == 0 { + opt[i][j] += opt[i][j+1] + } + } + } + fmt.Scanln() + for _, r := range opt { + fmt.Println(r) + } + return opt[0][0] +} + +func Test_countThePath(t *testing.T) { + grid := [][]int{ + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 1, 0, 0, 0, 1, 0}, + {0, 0, 0, 0, 1, 0, 0, 0}, + {1, 0, 1, 0, 0, 1, 0, 0}, + {0, 0, 1, 0, 0, 0, 0, 0}, + {0, 0, 0, 1, 1, 0, 1, 0}, + {0, 1, 0, 0, 0, 1, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + } + fmt.Println(countThePath(grid)) +} diff --git a/go.mod b/go.mod index 6224274..52e40fe 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module leetcode +module github.com/Aavon/leetcode go 1.12 diff --git a/s4/solution_test.go b/s4/solution_test.go new file mode 100644 index 0000000..2202a2f --- /dev/null +++ b/s4/solution_test.go @@ -0,0 +1,5 @@ +package s4 + +func solution() { + +}