add new solutions
This commit is contained in:
parent
d798d5e8c9
commit
886b5e0a8e
34 changed files with 1164 additions and 0 deletions
21
solutions/0/q64/solution.go
Normal file
21
solutions/0/q64/solution.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package q64
|
||||
|
||||
func minPathSum(grid [][]int) int {
|
||||
w, h := len(grid[0]), len(grid)
|
||||
|
||||
for y := 1; y < h; y++ {
|
||||
grid[y][0] += grid[y-1][0]
|
||||
}
|
||||
for x := 1; x < w; x++ {
|
||||
grid[0][x] += grid[0][x-1]
|
||||
}
|
||||
|
||||
for y := 1; y < h; y++ {
|
||||
for x := 1; x < w; x++ {
|
||||
grid[y][x] += min(grid[y-1][x], grid[y][x-1])
|
||||
}
|
||||
}
|
||||
return grid[h-1][w-1]
|
||||
}
|
||||
|
||||
var _ = minPathSum
|
||||
Loading…
Add table
Add a link
Reference in a new issue