mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 07:35:35 +08:00
Merge pull request #1884 from ShuBo6/master
bug&&typo: 0063不同路径II,0343整数拆分
This commit is contained in:
@ -338,6 +338,10 @@ class Solution:
|
|||||||
```go
|
```go
|
||||||
func uniquePathsWithObstacles(obstacleGrid [][]int) int {
|
func uniquePathsWithObstacles(obstacleGrid [][]int) int {
|
||||||
m, n := len(obstacleGrid), len(obstacleGrid[0])
|
m, n := len(obstacleGrid), len(obstacleGrid[0])
|
||||||
|
//如果在起点或终点出现了障碍,直接返回0
|
||||||
|
if obstacleGrid[m-1][n-1] == 1 || obstacleGrid[0][0] == 1 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
// 定义一个dp数组
|
// 定义一个dp数组
|
||||||
dp := make([][]int, m)
|
dp := make([][]int, m)
|
||||||
for i, _ := range dp {
|
for i, _ := range dp {
|
||||||
@ -362,8 +366,6 @@ func uniquePathsWithObstacles(obstacleGrid [][]int) int {
|
|||||||
}
|
}
|
||||||
return dp[m-1][n-1]
|
return dp[m-1][n-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Javascript
|
### Javascript
|
||||||
|
@ -94,7 +94,7 @@ dp[i] 是依靠 dp[i - j]的状态,所以遍历i一定是从前向后遍历,
|
|||||||
所以遍历顺序为:
|
所以遍历顺序为:
|
||||||
```CPP
|
```CPP
|
||||||
for (int i = 3; i <= n ; i++) {
|
for (int i = 3; i <= n ; i++) {
|
||||||
for (int j = 1; j <= i / 2; j++) {
|
for (int j = 1; j < i - 1; j++) {
|
||||||
dp[i] = max(dp[i], max((i - j) * j, dp[i - j] * j));
|
dp[i] = max(dp[i], max((i - j) * j, dp[i - j] * j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user