We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 90d0f7c commit 5683076Copy full SHA for 5683076
DP Problems/Unique-Paths-II.txt
@@ -0,0 +1,21 @@
1
+class Solution {
2
+ public int uniquePathsWithObstacles(int[][] grid) {
3
+ if (grid[0][0] == 1) {
4
+ return 0;
5
+ }
6
+ grid[0][0] = 1;
7
+ for (int i = 1; i < grid.length; i++) {
8
+ grid[i][0] = (grid[i][0] == 0 && grid[i-1][0] == 1) ? 1 : 0;
9
10
+ for (int j = 1; j < grid[0].length; j++) {
11
+ grid[0][j] = (grid[0][j] == 0 && grid[0][j-1] == 1) ? 1 : 0;
12
13
+
14
+ for (int n = 1; n < grid.length; n++) {
15
+ for (int m = 1; m < grid[n].length; m++) {
16
+ grid[n][m] = (grid[n][m] != 1) ? (grid[n-1][m] + grid[n][m-1]) : 0;
17
18
19
+ return grid[grid.length-1][grid[0].length-1];
20
21
+}
0 commit comments