Problem
A robot starts at the top-left of a grid and wants to reach the bottom-right, moving only right or down. Some cells are blocked: grid[r][c] == 1 is an obstacle the robot cannot enter, and 0 is open. Return how many different paths reach the bottom-right cell.
Example 1
grid = [[0, 0, 0],
Example 2
[0, 1, 0],
Example 3
- Input
- [0, 0, 0]]
- Output
- 2
- Why
- go around the middle on either side
Example 4
grid = [[0, 1],
Example 5
- Input
- [0, 0]]
- Output
- 1
If the start or the finish is an obstacle, the answer is 0.
Constraints
1 <= m, n <= 100 where the grid is m × ngrid[r][c] is 0 or 1The answer is at most 2 * 10^9.