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

Unique Paths II

时间:2015-04-15 07:12:37      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

public class Solution {
    public int uniquePathsWithObstacles(int[][] obstacleGrid) {
         if(obstacleGrid == null || obstacleGrid.length==0 || obstacleGrid[0].length==0)  return 0;
 
    int[] res= new int[ obstacleGrid[0].length];
    res[0]=1;
    for(int i=0; i< obstacleGrid.length; i++){
        for(int j=0; j< obstacleGrid[0].length;j++){
            if(obstacleGrid[i][j]==1){
                res[j]=0;
            }else{ 
                if(j>0)
                    res[j] += res[j-1];
            }
            
        }
    }
    return res[ obstacleGrid[0].length-1];
    
    }
}

ref http://blog.csdn.net/linhuanmars/article/details/22135231

Unique Paths II

标签:

原文地址:http://www.cnblogs.com/jiajiaxingxing/p/4427474.html

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