Leetcode之Unique Paths II 问题

问题描述:

Follow up for "Unique Paths":

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.

示例:

For example,
There is one obstacle in the middle of a 3x3 grid as illustrated below.

[

  [0,0,0],

  [0,1,0],

  [0,0,0]

]

问题来源:Unique Paths II (详细地址:https://leetcode.com/problems/unique-paths-ii/description/)

思路分析:Unique Paths 和这道题最大的区别就是,这道题设置了障碍,也就是说遇到1的时候,表示此路是行不通的,但是万变不离其宗,都是动态规划来解决,而且这里不当都设置第0行和第0列的值了,在这只设置dp[0] = 1,设置成1代表着只能是往右走第一行和往下走第一列,只有这一种选择,不能有别的方案。

代码:




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值