博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[LeetCode] Unique Paths II
阅读量:4585 次
发布时间:2019-06-09

本文共 1075 字,大约阅读时间需要 3 分钟。

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]]

The total number of unique paths is 2.

 

分析:类似于unique path

class Solution {public:    int uniquePathsWithObstacles(vector
>& obstacleGrid) { int m = obstacleGrid.size(); int n = obstacleGrid[0].size(); vector
> resu(m+1, vector
(n+1, 0)); resu[0][1] = 1; for (int i = 1; i <= m; i++) for (int j = 1; j <=n; j++) { if (obstacleGrid[i-1][j-1] == 1) { resu[i][j] = 0; } else { resu[i][j] = resu[i-1][j] + resu[i][j-1]; } } return resu[m][n]; }

 

转载于:https://www.cnblogs.com/vincently/p/4800189.html

你可能感兴趣的文章
Java String format 对%的处理
查看>>
跨平台移动应用开发AppCan开发文档阅读指南
查看>>
Lind.DDD敏捷领域驱动框架~介绍
查看>>
PHP自带函数给数字前补0或补位(转)
查看>>
iOS runtime实用篇--和常见崩溃say good-bye!
查看>>
细说Cookie
查看>>
Javascript 第二章
查看>>
几个常用算法及反射+多线程调用
查看>>
ubuntu12.04 上面配置blogilo的博客园客户端的步骤
查看>>
Codeforces Gym101170I:Iron and Coal(建多幅图+多次BFS)***
查看>>
Python杂俎 —— 自动压缩指定格式文件&自动删除
查看>>
2017年01月。。
查看>>
bcmath(精准数学的计算)
查看>>
ASP.NET的路由系统:根据路由规则生成URL
查看>>
ASP.NET Core Razor 视图起始页 - ASP.NET Core 基础教程 - 简单教程,简单编程
查看>>
从PRISM开始学WPF(四)Prism-Module?
查看>>
解决session阻塞的问题
查看>>
SQL Server 触发器
查看>>
css优先级计算规则
查看>>
Asp.Net Web API 2第十五课——Model Validation(模型验证)
查看>>