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]
- ]
- he total number of unique paths is 2.
- Note: m and n will be at most 100.
同Unique Paths的DP类似。
- class Solution {
- public:
- int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) {
- // Start typing your C/C++ solution below
- // DO NOT write int main() function
- int m = obstacleGrid.size();
- int n = obstacleGrid[].size();
- vector<vector<int>> grid(m, vector<int>(n,));
- for(int i = ; i< n; i++)
- if(obstacleGrid[][i] ==) grid[][i] = ;
- else break;
- for(int i = ; i< m; i++)
- if(obstacleGrid[i][] == ) grid[i][] = ;
- else break;
- for(int i = ; i< m; i++)
- for(int j = ; j< n; j++)
- if(obstacleGrid[i][j] == )
- grid[i][j] = grid[i-][j] + grid[i][j-];
- return grid[m-][n-];
- }
- };
LeetCode_Unique Paths II的更多相关文章
- LEETCODE —— Unique Paths II [动态规划 Dynamic Programming]
唯一路径问题II Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are ...
- 62. Unique Paths && 63 Unique Paths II
https://leetcode.com/problems/unique-paths/ 这道题,不利用动态规划基本上规模变大会运行超时,下面自己写得这段代码,直接暴力破解,只能应付小规模的情形,当23 ...
- 【leetcode】Unique Paths II
Unique Paths II Total Accepted: 22828 Total Submissions: 81414My Submissions Follow up for "Uni ...
- 61. Unique Paths && Unique Paths II
Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagra ...
- LeetCode: Unique Paths II 解题报告
Unique Paths II Total Accepted: 31019 Total Submissions: 110866My Submissions Question Solution Fol ...
- 【LeetCode练习题】Unique Paths II
Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...
- LeetCode之“动态规划”:Minimum Path Sum && Unique Paths && Unique Paths II
之所以将这三道题放在一起,是因为这三道题非常类似. 1. Minimum Path Sum 题目链接 题目要求: Given a m x n grid filled with non-negative ...
- [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 ...
- LEETCODE —— Unique Paths II [Dynamic Programming]
唯一路径问题II Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are ...
随机推荐
- BZOJ3538: [Usaco2014 Open]Dueling GPS
3538: [Usaco2014 Open]Dueling GPS Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 59 Solved: 36[Subm ...
- 51nod-正整数分组问题(基础方程DP-01背包)
正整数分组 将一堆正整数分为2组,要求2组的和相差最小. 例如:1 2 3 4 5,将1 2 4分为1组,3 5分为1组,两组和相差1,是所有方案中相差最少的. 思路: 这题的实质其实也是0-1背包问 ...
- windows server2012域服务器降级的方法
最近在一个新的网络环境里建立windows域服务器,准备建立主.备两台域服务器.在一台新服务器上面安装了windows2012R2并配置了DC服务.域和林的级别设置为Windows2012R2级别.在 ...
- [深入React] 6.组件
组件是react的大杀器,超出其他框架几百里 react 组件和dom一样也是树状结构,只能由上而下传递变量(或者调用),不可以兄弟间或者更远的发生关系,为的就是简单,而且工作的很好. 每个组件有自己 ...
- 转义字符和ASCII
一.字符(char) 数字(int) 屏幕显示 '\n' 10 换行 '\0' ...
- java 截取字符串 拆分字符串
例如 想要吧"90_python" 分成“90” 和“python” 从网上看到的方法: public class splitTest { public static void m ...
- Android开发之发送短信
本实例通过SmsManager的sendTextMessage方法实现发送短信关于SmsManager的具体解释大家能够參照:Android开发之SmsManager具体解释 实例执行效果图: 程序代 ...
- Android SDK Manager 无法更新SDK
Android SDK Manager 被墙后无法更新SDK 下载sdk时抛出错误:Failed to fetch URL http://dl-ssl.google.com/ 參考例如以下博客: ht ...
- 完全卸载sql2005
转自:http://www.cnblogs.com/mytechblog/articles/1883961.html 1.Stop 所有服务 2.在控制面板中卸载所有与SQL Server 2005相 ...
- speex的基本编码和解码流程
最近在研究speex的编码和解码流程 之前在IM上用到的都是发语音片段,这个很简单,只需要找到googlecode上gauss的代码,然后套一下就可以用了. 不过googlecode要关闭,有人将他导 ...