Unique Paths II
来源:互联网 发布:如何学习书法 知乎 编辑:程序博客网 时间:2024/06/11 03:48
class Solution {public: int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { const int m=obstacleGrid.size(); const int n=obstacleGrid[0].size(); if(obstacleGrid[0][0]==1 || obstacleGrid[m-1][n-1]==1) return 0; vector<vector<int>> dp(m,vector<int>(n,0)); for(int i=0;i<m;++i) { if(obstacleGrid[i][0]==1) break; else dp[i][0]=1; } for(int j=0;j<n;++j) { if(obstacleGrid[0][j]==1) break; else dp[0][j]=1; } for(int i=1;i<m;++i) { for(int j=1;j<n;++j) { if(obstacleGrid[i-1][j]==1&& obstacleGrid[i][j-1]!=1) dp[i][j]=dp[i][j-1]; if(obstacleGrid[i][j-1]==1 && obstacleGrid[i-1][j]!=1) dp[i][j]=dp[i-1][j]; if(obstacleGrid[i-1][j]!=1&& obstacleGrid[i][j-1]!=1) dp[i][j]=dp[i][j-1]+dp[i-1][j]; } } return dp[m-1][n-1]; }};
0 0
- Unique Paths & Unique Paths II
- Unique Paths &&Unique Paths II
- Unique Paths & Unique Paths II
- Unique Paths & Unique Paths II
- LeetCode: Unique Paths II
- [Leetcode] Unique Paths II
- LeetCode : Unique Paths II
- Unique Paths II
- [LeetCode] Unique Paths II
- unique paths II
- Unique Paths II
- [LeetCode]Unique Paths II
- Unique Paths II
- Unique Paths II
- Unique Paths II
- Unique Paths II
- [leetcode]Unique Paths II
- Unique Paths II
- Dynamics CRM 2015 Online Update1 UI界面的更新变化
- zabbix 拿shell步骤
- 封装 UnityEngine.Debug.Log 为Dll ,游戏发布关闭 Log 减少性能消耗
- 查询结果按中文拼音顺序排序
- 在Raspberry Pi上安装openni2_camera
- Unique Paths II
- stm8 16位定时器TIM1
- DeepLearning tutorial(7)深度学习框架Keras的使用-进阶
- 位图bitmap算法
- 数据结构:最小生成树(Prim算法)
- android Launcher3应用列表修改透明背景
- 黑马程序员IOS-OC语言-分类、协议
- jquery中的innerHTML和value函数获取textarea内容
- C++ STL priority_queue<> 用法