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.
2 parents d395ba2 + bae2e61 commit f57c5dbCopy full SHA for f57c5db
csharp/0063-unique-paths-ii.cs
@@ -0,0 +1,22 @@
1
+public class Solution {
2
+ public int UniquePathsWithObstacles(int[][] obstacleGrid) {
3
+ var rowLength = obstacleGrid.Length;
4
+ var colLength = obstacleGrid[0].Length;
5
+
6
+ int[] row = new int[colLength];
7
+ Array.Fill(row, 0);
8
+ row[colLength - 1] = 1;
9
10
+ for(int i = rowLength - 1; i >= 0; i--)
11
+ {
12
+ for(int j = colLength - 1; j >= 0; j--)
13
14
+ if(obstacleGrid[i][j] == 1)
15
+ row[j] = 0;
16
+ else if (j + 1 < colLength)
17
+ row[j] = row[j] + row[j + 1];
18
+ }
19
20
+ return row[0];
21
22
+}
0 commit comments