https://oj.leetcode.com/problems/unique-paths-ii/
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][n]; 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]; } }