leetcode@ [62/63] Unique Paths II
- class Solution {
- public:
- int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
- if(obstacleGrid.size()== || obstacleGrid[].size()==) return ;
- int m = obstacleGrid.size(), n = obstacleGrid[].size();
- if(obstacleGrid[m-][n-]==) return ;
- vector<vector<int> > dp(m);
- for(int i=;i<dp.size();++i) dp[i].resize(n);
- for(int i=;i<dp.size();++i){
- for(int j=;j<dp[i].size();++j) dp[i][j]=;
- }
- dp[][] = (obstacleGrid[][]==) ? : ;
- for(int i=;i<dp.size();++i){
- if(dp[i-][] && !obstacleGrid[i][]) dp[i][] = ;
- }
- for(int j=;j<dp[].size();++j){
- if(dp[][j-] && !obstacleGrid[][j]) dp[][j] = ;
- }
- for(int i=;i<dp.size();++i){
- for(int j=;j<dp[i].size();++j){
- if(i>= && !obstacleGrid[i-][j]) dp[i][j] += dp[i-][j];
- if(j>= && !obstacleGrid[i][j-]) dp[i][j] += dp[i][j-];
- }
- }
- return dp[m-][n-];
- }
- };
leetcode@ [62/63] Unique Paths II的更多相关文章
- 【LeetCode】63. Unique Paths II
Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...
- 【一天一道LeetCode】#63. Unique Paths II
一天一道LeetCode (一)题目 Follow up for "Unique Paths": Now consider if some obstacles are added ...
- 【LeetCode】63. Unique Paths II 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/unique-pa ...
- LeetCode OJ 63. Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- [leetcode DP]63. Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- <LeetCode OJ> 62. / 63. Unique Paths(I / II)
62. Unique Paths My Submissions Question Total Accepted: 75227 Total Submissions: 214539 Difficulty: ...
- leetcode 62. Unique Paths 、63. Unique Paths II
62. Unique Paths class Solution { public: int uniquePaths(int m, int n) { || n <= ) ; vector<v ...
- 【leetcode】62.63 Unique Paths
62. Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the di ...
- 62. Unique Paths && 63 Unique Paths II
https://leetcode.com/problems/unique-paths/ 这道题,不利用动态规划基本上规模变大会运行超时,下面自己写得这段代码,直接暴力破解,只能应付小规模的情形,当23 ...
随机推荐
- 使用程序获取整型数据和浮点型数据在内存中的表示---gyy整理
使用程序获取整型数据和浮点型数据在内存中的表示. C++中整型(int).短整型(short int).单精度浮点数(float).双精度浮点数(double)在内存中所占字节数不同,因此取值范围也不 ...
- 第二个C语言代码
有问题,还没找出哪里出错了 输入一串字符,问号结束 统计1~9各出现的次数 ******************************************************** ...
- 性能优化工具 MVC Mini Profiler
性能优化工具 MVC Mini Profiler MVC MiniProfiler是Stack Overflow团队设计的一款对ASP.NET MVC.WebForm 以及WCF 的性能分析的小程 ...
- GCC警告选项例解
程序员是追求完美的一族,即使是一般的程序员大多也都不想看到自己的程序中有甚至那么一点点的瑕疵.遇到任意一条编译器警告都坚决不放过.有人会说:我们可以使用比编译器更加严格的静态代码检查工具,如splin ...
- python set type 集合类型的数据介绍 (set frozenset)
python支持数学中的集合概念,如:通过in,not in 可以检查某元素是否在,不在集合中. python有两种集合类型,set(可以变的,不能哈希,不能用作字典的key),frozenset ...
- PC寄存器的真实状态
因为预取指令的关系,PC寄存器永远比当前的寄存器多两个指令,ARM模式为大8,Thumb模式为大2,这针对的是32bit的ARMv7的指令集 In ARM state, the value of th ...
- Android中Input型输入设备驱动原理分析<一>
话说Android中Event输入设备驱动原理分析还不如说Linux输入子系统呢,反正这个是没变的,在android的底层开发中对于Linux的基本驱动程序设计还是没变的,当然Android底层机制也 ...
- 【HDOJ】2385 Stock
水题,逆向做+优先级队列. /* 2385 */ #include <iostream> #include <sstream> #include <string> ...
- Android开发之在子线程中使用Toast
在子线程中使用Toast的时候,出现Force close. 错误提示:Can't create handler inside thread that has not called Looper.pr ...
- Codeforces 374A - Inna and Pink Pony
原题地址:http://codeforces.com/contest/374/problem/A 好久没写题目总结了,最近状态十分不好,无论是写程序还是写作业还是精神面貌……NOIP挂了之后总觉得缺乏 ...