63. Unique Paths II
生活随笔
收集整理的這篇文章主要介紹了
63. Unique Paths II
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
和Unique paths是一樣的
1 public int uniquePathsWithObstacles(int[][] obstacleGrid) { 2 if(obstacleGrid == null || obstacleGrid.length == 0 || obstacleGrid[0].length == 0) { 3 return 0; 4 } 5 int len = obstacleGrid[0].length; 6 int[] res = new int[len]; 7 res[0] = 1; 8 for(int i = 0; i < obstacleGrid.length; i++) { 9 for(int j = 0; j < len; j++) { 10 if(obstacleGrid[i][j] == 1) { 11 res[j] = 0; 12 } else { 13 if(j > 0) { 14 res[j] += res[j-1]; 15 } 16 } 17 } 18 } 19 return res[len-1]; 20 }注意的是:
1.內外循壞都要從0開始,因為第一行也可能不可以走,并不能像上一題一樣初始化成1
2. 第13行需要檢查一下j是不是第一個
沒啦!
轉載于:https://www.cnblogs.com/warmland/p/5260327.html
總結
以上是生活随笔為你收集整理的63. Unique Paths II的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 7.时间和日期
- 下一篇: 一个利用Dataflow实现的Actor