leetcode-63. Unique Paths II
来源:互联网 发布:51单片机毕业设计题库 编辑:程序博客网 时间:2024/06/06 14:18
https://leetcode.com/problems/unique-paths-ii/#/description
问题描述:
参考http://blog.csdn.net/u013275928/article/details/72629236
在这道题的基础上加入了阻碍元素。
思路解析:
这道题,没有用到额外的二维数组用来记录方法数,而是直接利用参数数组。当数组中有1的时候,将其置为0,其他的按照DP的过程来。
代码如下:
public class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { int m=obstacleGrid.length; int n=obstacleGrid[0].length; for(int i=0;i<m;i++) { for(int j=0;j<n;j++) { if(obstacleGrid[i][j]==1){ obstacleGrid[i][j]=0; }else if(i==0&&j==0) { obstacleGrid[i][j]=1; }else if(i==0) { obstacleGrid[i][j]=obstacleGrid[i][j-1]; }else if(j==0) { obstacleGrid[i][j]=obstacleGrid[i-1][j]; }else { obstacleGrid[i][j]=obstacleGrid[i][j-1]+obstacleGrid[i-1][j]; } } } return obstacleGrid[m-1][n-1]; }}
阅读全文
0 0
- LeetCode --- 63. Unique Paths II
- LeetCode 63.Unique Paths II
- [leetcode] 63.Unique Paths II
- [leetcode] 63.Unique Paths II
- Leetcode 63. Unique Paths II
- LeetCode 63. Unique Paths II
- [leetcode] 63. Unique Paths II
- leetcode 63. Unique Paths II
- 63. Unique Paths II LeetCode
- LeetCode 63. Unique Paths II
- [LeetCode]63. Unique Paths II
- leetcode 63. Unique Paths II
- LeetCode *** 63. Unique Paths II
- leetcode 63. Unique Paths II
- Leetcode:63. Unique Paths II
- LeetCode 63. Unique Paths II
- leetcode 63.Unique Paths II
- LeetCode 63. Unique Paths II
- Spring 依赖注入
- Qcon北京2017总结:测试角度看泛智能和大数据
- Android 开发过程中小知识点汇总
- *BST(二叉搜索树)
- pandas字符串函数
- leetcode-63. Unique Paths II
- 关于相对论的一个猜想——二维空间理论
- C中的volatile用法
- 腾讯云 Web 登录 Kubernetes 集群内容器功能实践
- 2017.05.22回顾
- Nonnegative Matrix Factorizations for Clustering(矩阵分解聚类)
- 微信公众平台开发----天气预报
- C#学习笔记(三)—–C#高级特性:实现迭代器的捷径
- Codeforces Round #415 (Div. 2) B. Summer sell-off