码迷,mamicode.com
首页 > 其他好文 > 详细

63. Unique Paths II

时间:2018-09-14 10:53:06      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:unique   public   res   int   pat   return   obs   row   uniq   

 1 class Solution {
 2     public int uniquePathsWithObstacles(int[][] obstacleGrid) {
 3         if(obstacleGrid == null) return 0;
 4         int row = obstacleGrid.length;
 5         int col = obstacleGrid[0].length;
 6         int[][] res = new int[row][col];
 7         if(obstacleGrid[0][0] != 1) {
 8             res[0][0] = 1;
 9         }
10 
11         for(int i = 0; i < row; i++) {
12             for(int j = 0; j < col; j++) {
13                 if(i == 0 && j == 0) continue;
14                 if(obstacleGrid[i][j] != 1) {
15                     if(i-1 < 0) {
16                         res[i][j] = res[i][j-1];
17                     }else if(j-1 < 0) {
18                         res[i][j] = res[i-1][j];
19                     }else {
20                         res[i][j] = res[i][j-1] + res[i-1][j];
21                     }
22                 }else {
23                     continue;
24                 }
25             }
26         }
27         return res[row-1][col-1];
28         
29     }
30 }

 

63. Unique Paths II

标签:unique   public   res   int   pat   return   obs   row   uniq   

原文地址:https://www.cnblogs.com/goPanama/p/9644563.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!