63. Unique Paths II Medium
1/**
2 * [63] Unique Paths II
3 *
4 * You are given an m x n integer array grid. There is a robot initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m-1][n-1]). The robot can only move either down or right at any point in time.
5 * An obstacle and space are marked as 1 or 0 respectively in grid. A path that the robot takes cannot include any square that is an obstacle.
6 * Return the number of possible unique paths that the robot can take to reach the bottom-right corner.
7 * The testcases are generated so that the answer will be less than or equal to 2 * 10^9.
8 *
9 * Example 1:
10 * <img alt="" src="https://assets.leetcode.com/uploads/2020/11/04/robot1.jpg" style="width: 242px; height: 242px;" />
11 * Input: obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]]
12 * Output: 2
13 * Explanation: There is one obstacle in the middle of the 3x3 grid above.
14 * There are two ways to reach the bottom-right corner:
15 * 1. Right -> Right -> Down -> Down
16 * 2. Down -> Down -> Right -> Right
17 *
18 * Example 2:
19 * <img alt="" src="https://assets.leetcode.com/uploads/2020/11/04/robot2.jpg" style="width: 162px; height: 162px;" />
20 * Input: obstacleGrid = [[0,1],[0,0]]
21 * Output: 1
22 *
23 *
24 * Constraints:
25 *
26 * m == obstacleGrid.length
27 * n == obstacleGrid[i].length
28 * 1 <= m, n <= 100
29 * obstacleGrid[i][j] is 0 or 1.
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/unique-paths-ii/
35// discuss: https://leetcode.com/problems/unique-paths-ii/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn unique_paths_with_obstacles(obstacle_grid: Vec<Vec<i32>>) -> i32 {
41 0
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_63() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.