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 ...
随机推荐
- KafkaSpout分析:配置
public KafkaSpout(SpoutConfig spoutConf) { _spoutConfig = spoutConf;} 基于0.93版本的Storm SpoutConfig继承自K ...
- PYTHON设计模式,创建型之工厂方法模式
我感觉和上一个差不多,可能不要动最要的地方吧... #!/usr/bin/evn python #coding:utf8 class Pizza(object): def prepare(self, ...
- ???????????? no permissions
1.一手鞋地址 google http://developer.android.com/tools/device.html 我处理的方法如下: 我的问题: android的版卡 在Ubuntu12.0 ...
- live555源码研究(三)------UsageEnvironment类
一.UsageEnvironment类作用 1,不使用的时候回收当前的使用环境. 2,对返回结果消息和错误消息的维护. 二.类UsageEnvironment继承关系图
- Altium Designer13 如何导出Gerber文件
参考<http://blog.sina.com.cn/s/blog_9b9a51990100zyyv.html> 版本:AD13.3.4 目的:Gerber文件导出备忘 目录: Step1 ...
- Android TextView和EditText属性详解
TextView属性详解: autoLink设置 是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none/web /email/phone/map/all) ...
- MapReduce编程系列 — 3:数据去重
1.项目名称: 2.程序代码: package com.dedup; import java.io.IOException; import org.apache.hadoop.conf.Configu ...
- RabbitMQ安装和配置
RabbitMQ: MQ:message queue.MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过读写出入队列的消息(针对应用程序的数据)来 ...
- Oracle数据库生成UUID
从Data Ghost的blog得知,原来可以用Oracle来生成UUID,做法很简单,如下: select sys_guid() from dual; 数据类型是 raw(16) 有32个字符.
- SHA-1加密
/** * SHA-1加密 * @param strSrc 要加密的字符串 * @return 加密后的字符串 */ public static String SHAEncrypt(String st ...