LeetCode 62 Unique Paths II
来源:互联网 发布:icm20602中文数据手册 编辑:程序博客网 时间:2024/05/16 08:30
Follow up for "Unique Paths":
Now consider if some obstacles are added to the grids. How many unique paths would there be?
An obstacle and empty space is marked as 1
and 0
respectively in the grid.
For example,
There is one obstacle in the middle of a 3x3 grid as illustrated below.
[ [0,0,0], [0,1,0], [0,0,0]]
The total number of unique paths is 2
.
Note: m and n will be at most 100.
思路:与LeetCode 61 Unique Paths 的思路一样点http://blog.csdn.net/mlweixiao/article/details/37569159
public class Solution {public int uniquePathsWithObstacles(int[][] obstacleGrid) {int m = obstacleGrid.length;int n = obstacleGrid[0].length;int[][] grid = new int[m][n];int i, j;boolean flag = false;for (i = 0; i < m; i++) {if (obstacleGrid[i][0] == 1)flag = true;if (!flag)grid[i][0] = 1;}flag = false;for (i = 0; i < n; i++) {if (obstacleGrid[0][i] == 1)flag = true;if (!flag)grid[0][i] = 1;}for (i = 1; i < m; i++) {for (j = 1; j < n; j++) {if (obstacleGrid[i][j] == 0)grid[i][j] = grid[i - 1][j] + grid[i][j - 1];}}return grid[m - 1][n - 1];}}
0 0
- LeetCode 62 Unique Paths II
- LeetCode: Unique Paths II
- [Leetcode] Unique Paths II
- LeetCode : Unique Paths II
- [LeetCode] Unique Paths II
- [LeetCode]Unique Paths II
- [leetcode]Unique Paths II
- LeetCode-Unique Paths II
- [leetcode] Unique Paths II
- LeetCode - Unique Paths II
- LeetCode:Unique Paths II
- 【LeetCode】Unique Paths II
- leetcode Unique Paths II
- LeetCode Unique Paths II
- LeetCode | Unique Paths II
- Leetcode: Unique Paths II
- LeetCode Unique Paths II
- Unique Paths II -- LeetCode
- stm32中如何开关总中断
- EBS Form开发 弹性域定义中的参数<三>
- spring MVC配置详解
- Python中执行系统命令常见方法有两种:
- Linux命令yum
- LeetCode 62 Unique Paths II
- spring3 集成tiles3
- 指针作为函数参数传递时需要注意的问题
- js日期时间函数
- airMAX 基站远程管理_莱桥通信张景
- EBS Form开发中弹性域的定义语法
- IAP-应用内购买(部分)
- hdu4884TIANKENG’s rice shop(模拟)
- 在打印时屏蔽系统弹出对话框中的按钮