unique path II 动态规划 用一位数组完成
来源:互联网 发布:mysql 按月查询 编辑:程序博客网 时间:2024/06/14 05:32
上面这个是我自己写的 用二维数组 记录到达每个位置的路径个数、
public int uniquePathsWithObstacles(int[][] g) { if(g.length==0||g==null) return 0; int m=g.length; int n=g[0].length; int[][] r=new int[m][n]; for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ if(g[i][j]==1){ r[i][j]=0; }else{ if(i==0&&j==0){ r[i][j]=1; }else if(i==0){ r[i][j]=r[i][j-1]; }else if(j==0){ r[i][j]=r[i-1][j]; }else{ r[i][j]=r[i][j-1]+r[i-1][j]; } } } } return r[m-1][n-1]; }
public int uniquePathsWithObstacles(int[][] obstacleGrid) { int width = obstacleGrid[0].length; int[] dp = new int[width]; dp[0] = 1; for (int[] row : obstacleGrid) { for (int j = 0; j < width; j++) { if (row[j] == 1) dp[j] = 0; else if (j > 0) dp[j] += dp[j - 1]; } } return dp[width - 1];}
- unique path II 动态规划 用一位数组完成
- Leetcode 动态规划 Unique Paths II
- 动态规划——unique-paths-ii
- 动态规划问题系列---Unique Paths II
- leetcode做题总结,动态规划I(Triangle,Unique PathsI/II,Minimum Path Sum,Climbing Stairs,Jump Game,Word Break)
- Unique Path II
- [Leetcode]Unique Path II
- 10.3 Unique Path II
- [leetcode] Unique Path II
- Unique Path II--LeetCode
- Unique path ii
- Unique Path II
- [Leetcode]Unique Path II
- Unique Path II
- Leetcode Unique Path II
- Unique Paths II 动态规划(重重重)
- leetcode 63. Unique Paths II-唯一路径|动态规划
- 63. Unique Paths II 动态规划的问题
- SPSS变量定义
- Educational Codeforces Round 15
- program files文件夹和program files(x86)文件夹
- 排序算法之选择排序
- Android中asset文件夹和res/raw文件夹区别
- unique path II 动态规划 用一位数组完成
- 【cqbzoj1510】 遇见 滚动数组 dp 解题报告
- C语言指针总结
- 暑期工作日志-Day19
- 我的反思之路
- tjut 3573
- 网易校园招聘2017编程题--回文数问题
- Spring1.基础知识
- oracle拆分逗号分隔字符串 实现split