[leetcode]Unique Paths II
2013-07-26 18:05
281 查看
class Solution { public: int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) { // Start typing your C/C++ solution below // DO NOT write int main() function if(obstacleGrid.empty()) return 0; int m = obstacleGrid.size(); int n = obstacleGrid[0].size(); vector<vector<int>> f(m, vector<int>(n, 0)); for(int j = 0; j < n; j++){ if(obstacleGrid[0][j] == 1){ break; }else{ f[0][j] = 1; } } for(int i = 0; i < m; i++){ if(obstacleGrid[i][0] == 1){ break; }else{ f[i][0] = 1; } } for(int i = 1; i < m; i++){ for(int j = 1; j < n; j++){ if(obstacleGrid[i][j] == 1){ f[i][j] = 0; }else{ f[i][j] = f[i-1][j] + f[i][j-1]; } } } return f[m-1][n-1]; } };
相关文章推荐
- 【leetcode刷题笔记】Unique Paths II
- [LeetCode] Unique Paths II
- LeetCode_OJ【63】Unique Paths II
- LeetCode | Unique Paths I,II
- LeetCode_63---Unique Paths II
- [leetcode][DP] Unique Paths II
- 【LeetCode】Unique Paths II
- Leetcode Unique Paths II
- LeetCode Unique Paths II(dp)
- 【leetcode】Unique Paths I & II
- [LeetCode] Unique Paths、Unique Paths II、Minimum Path Sum
- LeetCode - Unique Paths II - Frequent
- leetcode -- Unique Paths II
- leetcode63-Unique Paths II
- [LeetCode] Unique Paths && Unique Paths II && Minimum Path Sum (动态规划之 Matrix DP )
- [Leetcode]Unique Paths II
- Leetcode[63]-Unique Paths II
- leetcode_question_63 Unique Paths II
- Leetcode 63:Unique Paths II
- [LeetCode] Unique Paths II