-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xieliwei
committed
Nov 23, 2020
1 parent
6de7e54
commit bf47be8
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module leetcode | ||
module github.com/Aavon/leetcode | ||
|
||
go 1.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package s4 | ||
|
||
func solution() { | ||
|
||
} |