mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 20:40:39 +08:00
添加 0063.不同路径II.md Rust版本
添加 0063.不同路径II.md Rust版本
This commit is contained in:
@ -384,6 +384,42 @@ function uniquePathsWithObstacles(obstacleGrid: number[][]): number {
|
||||
};
|
||||
```
|
||||
|
||||
### Rust
|
||||
|
||||
```Rust
|
||||
impl Solution {
|
||||
pub fn unique_paths_with_obstacles(obstacle_grid: Vec<Vec<i32>>) -> i32 {
|
||||
let m: usize = obstacle_grid.len();
|
||||
let n: usize = obstacle_grid[0].len();
|
||||
if obstacle_grid[0][0] == 1 || obstacle_grid[m-1][n-1] == 1 {
|
||||
return 0;
|
||||
}
|
||||
let mut dp = vec![vec![0; n]; m];
|
||||
for i in 0..m {
|
||||
if obstacle_grid[i][0] == 1 {
|
||||
break;
|
||||
}
|
||||
else { dp[i][0] = 1; }
|
||||
}
|
||||
for j in 0..n {
|
||||
if obstacle_grid[0][j] == 1 {
|
||||
break;
|
||||
}
|
||||
else { dp[0][j] = 1; }
|
||||
}
|
||||
for i in 1..m {
|
||||
for j in 1..n {
|
||||
if obstacle_grid[i][j] == 1 {
|
||||
continue;
|
||||
}
|
||||
dp[i][j] = dp[i-1][j] + dp[i][j-1];
|
||||
}
|
||||
}
|
||||
dp[m-1][n-1]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### C
|
||||
|
||||
```c
|
||||
|
Reference in New Issue
Block a user