[LeetCode]63 Unique Paths II
2015-01-04 09:16
357 查看
https://oj.leetcode.com/problems/unique-paths-ii/
http://blog.csdn.net/linhuanmars/article/details/22135231
http://blog.csdn.net/linhuanmars/article/details/22135231
public class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { // Validations if (obstacleGrid == null || obstacleGrid.length == 0 || obstacleGrid[0].length == 0) return 0; // Invalid input int m = obstacleGrid.length; int n = obstacleGrid[0].length; int[][] paths = new int[m] ; for (int i = 0 ; i < m ; i ++) { for (int j = 0 ; j < n ; j ++) { int v = 0; if (obstacleGrid[i][j] == 1) { // obstacle v = 0; } else if (i == 0 && j == 0) { // Start point v = 1; } else { int left = j > 0 ? paths[i][j - 1] : 0; int up = i > 0 ? paths[i - 1][j] : 0; v = left + up; } paths[i][j] = v; } } return paths[m - 1][n - 1]; } }
相关文章推荐
- LeetCode_OJ【63】Unique Paths II
- leetcode-62&63 Unique Paths I & II
- LeetCode(63) Unique Paths II
- Leetcode 63 Unique Paths II
- LeetCode题库解答与分析——#63.不同路径IIUniquePathsII
- Leetcode 63:Unique Paths II
- Unique Paths II - LeetCode 63
- LeetCode 62 Unique Paths & 63 Unique Paths II
- 【LeetCode】C# 63、Unique Paths II
- Leetcode:63. Unique Paths II
- LeetCode63 Unique Paths II
- LeetCode 63 — Unique Paths II(C++ Java Python)
- 【leetcode】【63】Unique Paths II
- [leetcode-63]Unique Paths II(c)
- Leetcode(62)(63) Unique Paths I II
- LeetCode63——Unique Paths II
- leetcode 63:Unique Paths II
- LeetCode(63)Unique Paths II
- [leetcode 63] Unique Paths II
- LeetCode 63: Unique Paths II