【LeetCode】Unique Paths II
2014-11-25 11:33
295 查看
class Solution { public: int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) { int m = obstacleGrid.size(); int n = obstacleGrid[0].size(); vector<vector<int>> result(m,vector<int>(n)); int i, j; result[0][0] = obstacleGrid[0][0] == 1 ? 0 : 1; for (i = 1; i < m; i++) { result[i][0] = obstacleGrid[i][0] == 1 ? 0 : result[i - 1][0]; } for (j = 1; j < n; j++) { result[0][j] = obstacleGrid[0][j] == 1 ? 0 : result[0][j - 1]; } for (i = 1; i < m; i++) { for (j = 1; j < n; j++) { result[i][j] = obstacleGrid[i][j] == 1 ? 0 : result[i - 1][j] + result[i][j - 1]; } } return result[m - 1][n - 1]; } };
相关文章推荐
- 开始刷leetcode day60: Unique Paths II
- leetcode unique paths ii
- 动态规划小结 - 二维动态规划 - 时间复杂度 O(n*n)的棋盘型,题 [LeetCode] Minimum Path Sum,Unique Paths II,Edit Distance
- Leetcode Unique Paths II
- LeetCode-Unique Paths II
- leetcode63-Unique Paths II
- LeetCode: Unique Paths II
- LeetCode_Unique Paths II
- [Leetcode]Unique Paths II
- Leetcode 动态规划 Unique Paths II
- [Leetcode]Unique Paths II
- LeetCode-Unique Paths II
- Unique Paths II - LeetCode 63
- [LeetCode] Unique Paths II
- leetcode Unique Paths & Unique Paths II & Minimum Path Sum
- LeetCode Unique Paths II
- leetcode ---Unique Paths II
- leetcode || 63、Unique Paths II
- [LeetCode] 124: Unique Paths II
- LeetCode--Unique Paths II