Skip to content

Commit

Permalink
mod
Browse files Browse the repository at this point in the history
  • Loading branch information
xieliwei committed Nov 23, 2020
1 parent 6de7e54 commit bf47be8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
53 changes: 53 additions & 0 deletions dp/dp_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module leetcode
module github.com/Aavon/leetcode

go 1.12
5 changes: 5 additions & 0 deletions s4/solution_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package s4

func solution() {

}

0 comments on commit bf47be8

Please sign in to comment.