标签:
public class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { int row = obstacleGrid.length; if (row == 0) { return 0; } int col = obstacleGrid[0].length; if (obstacleGrid[0][0] == 1) { return 0; } int[][] record = new int[row][col]; record[0][0] = 1; for (int r = 1; r < row; r++) { if (obstacleGrid[r][0] == 1 || record[r - 1][0] == 0) { } else { record[r][0] = record[r - 1][0]; } } for (int c = 1; c < col; c++) { if (obstacleGrid[0][c] == 1 || record[0][c - 1] == 0) { } else { record[0][c] = record[0][c - 1]; } } for (int r = 1; r < row; r++) { for (int c = 1; c < col; c++) { if (obstacleGrid[r][c] == 1) { record[r][c] = 0; } else { record[r][c] = record[r - 1][c] + record[r][c - 1]; } } } return record[row - 1][col - 1]; } }
标签:
原文地址:http://www.cnblogs.com/vision-love-programming/p/5019735.html