A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

Now consider if some obstacles are added to the grids. How many unique paths would there be?

An obstacle and empty space is marked as 1 and 0 respectively in the grid.

Note: m and n will be at most 100.

Example 1:

Input:
[   [0,0,0],   [0,1,0],   [0,0,0]
]
Output: 2
Explanation:
There is one obstacle in the middle of the 3x3 grid above.
There are two ways to reach the bottom-right corner:
1. Right -> Right -> Down -> Down
2. Down -> Down -> Right –> Right
想法:与Unique Path类似,只不过需要考虑障碍物,将有障碍物出现的地方,result设置为0.如何m-1,n-1位置有障碍物,直接返回0
class Solution {
public:
    int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
        int row =  obstacleGrid.size();
        ].size();
        int result[row][col];
         ; i < row ; i++){
             ; j < col ; j++){
                ){
                    result[i][j] = ;
                }else{
                     && j == ){
                        result[i][j] = ;
                    }else{
                        result[i][j] = ;
                         >=  ){
                            result[i][j] += result[i-][j];
                        }
                         >=  ){
                            result[i][j] += result[i][j-];
                        }
                        }

                }

            }
        }
        ][col-];
    }
};

leetcode63—Unique Path II的更多相关文章

  1. LeetCode 63. Unique Path II(所有不同路径之二)

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  2. Unique path ii

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  3. leetcode-63. Unique Paths II · DP + vector

    题面 A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...

  4. LeetCode63 Unique Paths II

    题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...

  5. Leetcode63.Unique Paths II不同路径2

    一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为"Start" ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为" ...

  6. LeetCode之“动态规划”:Minimum Path Sum && Unique Paths && Unique Paths II

    之所以将这三道题放在一起,是因为这三道题非常类似. 1. Minimum Path Sum 题目链接 题目要求: Given a m x n grid filled with non-negative ...

  7. [LeetCode] Unique Paths && Unique Paths II && Minimum Path Sum (动态规划之 Matrix DP )

    Unique Paths https://oj.leetcode.com/problems/unique-paths/ A robot is located at the top-left corne ...

  8. 动态规划小结 - 二维动态规划 - 时间复杂度 O(n*n)的棋盘型,题 [LeetCode] Minimum Path Sum,Unique Paths II,Edit Distance

    引言 二维动态规划中最常见的是棋盘型二维动态规划. 即 func(i, j) 往往只和 func(i-1, j-1), func(i-1, j) 以及 func(i, j-1) 有关 这种情况下,时间 ...

  9. 【LeetCode】63. Unique Paths II

    Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...

随机推荐

  1. A计划 hdu2102(bfs一般题)

    A计划 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  2. POJ3694(KB9-D 割边+LCA)

    Network Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 10371   Accepted: 3853 Descript ...

  3. 卸载阿里云自带svn

  4. JavaScript判断值是否是NaN

    第一种方法: if (!Number.isNaN) { Number.isNaN = function (n) { return ( typeof n === 'number' && ...

  5. webpack打包小图片时进行Base64转码

    关于base64 优点: base64就是一串字符串码表示的图片,在加载页面和js时一块加载出来,减少了加载图片时的http请求.加载一张图片时会发起一次http请求,http请求每次建立都会需要一定 ...

  6. CF712E Memory and Casinos

    设\(f[i]\)为从\(i\)到\(r+1\)且不走出区间的概率 \(f[i]=p[i]f[i+1]+(1-p[i])f[i-1]\) \(f[i]-f[i-1]=p[i](f[i+1]-f[i-1 ...

  7. vue Element-UI 分页使用(1)

    最近在使用Element-UI这套框架配合Vue来写前端页面.在用Element-UI来制作表格的时候,遇到了一些小问题,记录方便学习. 其中两个事件是关于切换当前页和切换显示的列表条数的.另外的属性 ...

  8. Sqoop安装与应用过程

    1.  参考说明 参考文档: http://sqoop.apache.org/ http://sqoop.apache.org/docs/1.99.7/admin/Installation.html ...

  9. 安卓开发环境配置之Windows+ADT+eclipse

    安卓环境搭建之Windows+ADT+eclipse 要点: 1.安装JDK 2.安装Android SDK 3.安装eclipse 4.安装ADT 5.安装调试环境 正文: 1.安装JDK 1.1准 ...

  10. python + Jenkins + requests 数据驱动接口测试 环境部署

    ** Jenkins安装: * 安装包选择:Jenkins.war * windows下有msi和war两种格式,我使用的是war,下载下来丢到xmapp的指定目录就行,操作方便一点      * m ...