leetcode 63 简单题

题目很水。。。

直接放代码了

int uniquePathsWithObstacles(int** obstacleGrid, int obstacleGridRowSize, int obstacleGridColSize) {
    int path[obstacleGridRowSize][obstacleGridColSize];
    if(obstacleGrid[0][0]==1)
        path[0][0] = 0;
    else
        path[0][0] = 1;
    for(int i =1;i<obstacleGridRowSize;i++)
        if(obstacleGrid[i][0]==0&&path[i-1][0]==1)
            path[i][0] = 1;
        else
            path[i][0] = 0;
    for(int i =1;i<obstacleGridColSize;i++)
        if(obstacleGrid[0][i]==0&&path[0][i-1]==1)
            path[0][i] = 1;
        else
            path[0][i] = 0;
    for(int i =1;i<obstacleGridRowSize;i++)
        for(int j =1;j<obstacleGridColSize;j++)
        {
            if(obstacleGrid[i][j]==0)
                path[i][j] = path[i-1][j]+path[i][j-1];
            else
                path[i][j] = 0;
        }
    return path[obstacleGridRowSize-1][obstacleGridColSize-1];
}

 

posted @ 2018-05-09 11:41  Cheney_1016  阅读(104)  评论(0编辑  收藏  举报