當(dāng)前位置:
首頁(yè) >
63. Unique Paths II
發(fā)布時(shí)間:2025/7/14
29
豆豆
生活随笔
收集整理的這篇文章主要介紹了
63. Unique Paths II
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
和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.內(nèi)外循壞都要從0開(kāi)始,因?yàn)榈谝恍幸部赡懿豢梢宰?#xff0c;并不能像上一題一樣初始化成1
2. 第13行需要檢查一下j是不是第一個(gè)
沒(méi)啦!
轉(zhuǎn)載于:https://www.cnblogs.com/warmland/p/5260327.html
總結(jié)
以上是生活随笔為你收集整理的63. Unique Paths II的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 7.时间和日期
- 下一篇: 一个利用Dataflow实现的Actor