|
| 1 | +<h2><a href="https://leetcode.com/problems/unique-paths-ii/">63. Unique Paths II</a></h2><h3>Medium</h3><hr><div><p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any point in time.</p> |
| 2 | + |
| 3 | +<p>An obstacle and space are marked as <code>1</code> or <code>0</code> respectively in <code>grid</code>. A path that the robot takes cannot include <strong>any</strong> square that is an obstacle.</p> |
| 4 | + |
| 5 | +<p>Return <em>the number of possible unique paths that the robot can take to reach the bottom-right corner</em>.</p> |
| 6 | + |
| 7 | +<p>The testcases are generated so that the answer will be less than or equal to <code>2 * 10<sup>9</sup></code>.</p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | +<img alt="" src="https://assets.leetcode.com/uploads/2020/11/04/robot1.jpg" style="width: 242px; height: 242px;"> |
| 12 | +<pre><strong>Input:</strong> obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]] |
| 13 | +<strong>Output:</strong> 2 |
| 14 | +<strong>Explanation:</strong> There is one obstacle in the middle of the 3x3 grid above. |
| 15 | +There are two ways to reach the bottom-right corner: |
| 16 | +1. Right -> Right -> Down -> Down |
| 17 | +2. Down -> Down -> Right -> Right |
| 18 | +</pre> |
| 19 | + |
| 20 | +<p><strong class="example">Example 2:</strong></p> |
| 21 | +<img alt="" src="https://assets.leetcode.com/uploads/2020/11/04/robot2.jpg" style="width: 162px; height: 162px;"> |
| 22 | +<pre><strong>Input:</strong> obstacleGrid = [[0,1],[0,0]] |
| 23 | +<strong>Output:</strong> 1 |
| 24 | +</pre> |
| 25 | + |
| 26 | +<p> </p> |
| 27 | +<p><strong>Constraints:</strong></p> |
| 28 | + |
| 29 | +<ul> |
| 30 | + <li><code>m == obstacleGrid.length</code></li> |
| 31 | + <li><code>n == obstacleGrid[i].length</code></li> |
| 32 | + <li><code>1 <= m, n <= 100</code></li> |
| 33 | + <li><code>obstacleGrid[i][j]</code> is <code>0</code> or <code>1</code>.</li> |
| 34 | +</ul> |
| 35 | +</div> |
0 commit comments