一天一道LeetCode
(一)题目
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.
(二)解题
解题思路:参考上一篇博文【一天一道LeetCode】#62. Unique Paths
class Solution {
public:
int dp[101][101];
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
int row = obstacleGrid.size();
int col = 0;
if(row!=0) col = obstacleGrid[0].size();
if(obstacleGrid[0][0]==1) return 0;//起始点不通则直接返回0
for(int i = row-1 ; i>=0 ; i--)
for(int j = col-1 ; j>=0 ; j--)
{
if(obstacleGrid[i][j]==1) dp[i][j] = 0;//代表此路不通
else if(i==row-1&&j==col-1) dp[i][j] = 1;//规定终点的dp为1
else dp[i][j] = dp[i+1][j]+dp[i][j+1];
}
return dp[0][0];
}
【一天一道LeetCode】#63. Unique Paths II的更多相关文章
-
LeetCode 63. Unique Paths II不同路径 II (C++/Java)
题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
-
[LeetCode] 63. Unique Paths II 不同的路径之二
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
-
leetcode 63. Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
-
LeetCode: 63. Unique Paths II(Medium)
1. 原题链接 https://leetcode.com/problems/unique-paths-ii/description/
-
[leetcode] 63. Unique Paths II (medium)
原题 思路: 用到dp的思想,到row,col点路径数量 : path[row][col]=path[row][col-1]+path[row-1][col]; 遍历row*col,如果map[row ...
-
leetcode 62. Unique Paths 、63. Unique Paths II
62. Unique Paths class Solution { public: int uniquePaths(int m, int n) { || n <= ) ; vector<v ...
-
【LeetCode】63. Unique Paths II
Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...
-
62. Unique Paths &;&; 63 Unique Paths II
https://leetcode.com/problems/unique-paths/ 这道题,不利用动态规划基本上规模变大会运行超时,下面自己写得这段代码,直接暴力破解,只能应付小规模的情形,当23 ...
-
[Leetcode Week12]Unique Paths II
Unique Paths II 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/unique-paths-ii/description/ Descrip ...
-
【leetcode】Unique Paths II
Unique Paths II Total Accepted: 22828 Total Submissions: 81414My Submissions Follow up for "Uni ...
随机推荐
-
H5+Mui文件配置 vue-resource基本使用方法
使用HBuilder空项目搭建h5原生开发框架需要的文件配置: *css:mui.min.css *fonts:mui.ttf mui-icon-extra.ttf *js:mui.js mui.mi ...
-
texturepacker打包图片,场景切换时背景图有黑边
在使用TexturePacker打包图片之后,背景图在场景切换(有切换动画)时,明显能看到有黑边,在百度之后解决了. 知乎上边有网友贴出了两种解决方法,我抄过来如下: 第一种: 修改 ccConfig ...
-
IOS 开发下拉刷新和上拉加载更多
IOS 开发下拉刷新和上拉加载更多 简介 1.常用的下拉刷新的实现方式 (1)UIRefreshControl (2)EGOTTableViewrefresh (3)AH3DPullRefresh ( ...
-
Lojic X
媒体 赫兹 电话 500HZ 网络数据 8000HZ CD 44100HZ 电脑 48000HZ DVD 96000HZ 最大值(蓝光) 192000HZ 横向———————— 清晰度 ...
-
YII中表单验证
关于表单的验证有三种: 1.yii的客户端验证 2.yii的服务器端验证 3.yii的ajax验证 例如: 1.在表单对应的模型中定义一个rules方法(该方添加后,在表单提交时,将自动被调用) pu ...
-
Android studio修改debug.keystore
在android studio项目中配置自定义的debug keystore 方法/步骤 在项目的build.gradle中添加如下内容: android { signingConfigs ...
-
《Java4Android视频教程》学习笔记(一)
此为个人的学习笔记,所以不具备太强的学习性,若有错误请谅解,如果能指出我的错误,我将万分感谢~ 一:java历史 java诞生 前身:Oak->java 曾经的名字C++(++--) 原意是在C ...
-
SQL Server 2008性能故障排查(二)——CPU
原文:SQL Server 2008性能故障排查(二)--CPU 承接上一篇:SQL Server 2008性能故障排查(一)--概论 说明一下,CSDN的博客编辑非常不人性化,我在word里面都排好 ...
-
ios-贝塞尔曲线
git下载地址:git@github.com:lu459700780/UIBezierPath.git 演示: #import "ViewController.h" @interf ...
-
Android文本框-android学习之旅(十七 )
文本框简介 文本框属于基本的andoid控件,TextView继承了View是最基本的文本框,它的子类包括EditView和Button等,TextView的大部分方法,它的子类也可以使用. Text ...