Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fdf12b6

Browse files
Merge pull request youngyangyang04#2030 from fwqaaq/patch-37
Update 0063.不同路径II.md about rust
2 parents faa7de2 + ced650c commit fdf12b6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎problems/0063.不同路径II.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,33 @@ impl Solution {
493493
}
494494
```
495495
496+
空间优化:
497+
498+
```rust
499+
impl Solution {
500+
pub fn unique_paths_with_obstacles(obstacle_grid: Vec<Vec<i32>>) -> i32 {
501+
let mut dp = vec![0; obstacle_grid[0].len()];
502+
for (i, &v) in obstacle_grid[0].iter().enumerate() {
503+
if v == 0 {
504+
dp[i] = 1;
505+
} else {
506+
break;
507+
}
508+
}
509+
for rows in obstacle_grid.iter().skip(1) {
510+
for j in 0..rows.len() {
511+
if rows[j] == 1 {
512+
dp[j] = 0;
513+
} else if j != 0 {
514+
dp[j] += dp[j - 1];
515+
}
516+
}
517+
}
518+
dp.pop().unwrap()
519+
}
520+
}
521+
```
522+
496523
### C
497524
498525
```c

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /