diff --git a/UniquePathII/step1.md b/UniquePathII/step1.md new file mode 100644 index 0000000..e35fcda --- /dev/null +++ b/UniquePathII/step1.md @@ -0,0 +1,35 @@ +```java +class Solution { + public int uniquePathsWithObstacles(int[][] grid) { + int m = grid.length; + int n = grid[0].length; + int[][] dp = new int[m][n]; + + for (int y = 0; y < m; y++) { + for (int x = 0; x < n; x++) { + if (grid[y][x] == 1) { + continue; + } + if (x == 0 && y == 0) { + dp[y][x] = 1; + continue; + } + + if (x == 0) { + dp[y][x] = dp[y - 1][x]; + continue; + } + + if (y == 0) { + dp[y][x] = dp[y][x - 1]; + continue; + } + + dp[y][x] = dp[y - 1][x] + dp[y][x - 1]; + } + } + + return dp[m - 1][n - 1]; + } +} +```