Skip to content

Commit

Permalink
添加0062.不同路径.md C语言滚动数组解法
Browse files Browse the repository at this point in the history
  • Loading branch information
KingArthur0205 committed Jan 25, 2023
1 parent d3b241e commit 31e6a1a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions problems/0062.不同路径.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,26 @@ int uniquePaths(int m, int n){
}
```
滚动数组解法:
```c
int uniquePaths(int m, int n){
int i, j;
// 初始化dp数组
int *dp = (int*)malloc(sizeof(int) * n);
for (i = 0; i < n; ++i)
dp[i] = 1;
for (j = 1; j < m; ++j) {
for (i = 1; i < n; ++i) {
// dp[i]为二维数组解法中dp[i-1][j]。dp[i-1]为二维数组解法中dp[i][j-1]
dp[i] += dp[i - 1];
}
}
return dp[n - 1];
}
```

### Scala

```scala
Expand Down

0 comments on commit 31e6a1a

Please sign in to comment.