java 63. Unique Paths II(#)。java
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 63. Unique Paths II(#)。java相关的知识,希望对你有一定的参考价值。
public class Solution {
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
if (obstacleGrid == null || obstacleGrid.length < 1 || obstacleGrid[0].length < 1) return 0;
int m = obstacleGrid.length;
int n = obstacleGrid[0].length;
int[][] dp = new int[m][n];
int ii = 0;
while (ii < m && obstacleGrid[ii][0] == 0) {
dp[ii++][0] = 1;
}
int jj = 0;
while (jj < n && obstacleGrid[0][jj] == 0) {
dp[0][jj++] = 1;
}
for (int i = 1; i < m; i++) {
for (int j = 1; j < n; j++) {
if (obstacleGrid[i][j] != 1) {
dp[i][j] = (obstacleGrid[i - 1][j] == 1 ? 0 : dp[i - 1][j]) +
(obstacleGrid[i][j - 1] == 1 ? 0 : dp[i][j - 1]);
}
}
}
return dp[m-1][n-1];
}
}
以上是关于java 63. Unique Paths II(#)。java的主要内容,如果未能解决你的问题,请参考以下文章
java 63. Unique Paths II(#)。java
java 63. Unique Paths II(#)。java
java 63. Unique Paths II(#)。java
63. Unique Paths II java solutions
LeetCode 63. Unique Paths II Java
63. Unique Paths II