Skip to content

Commit bae2e61

Browse files
committed
Create 0063-unique-paths-ii.cs
1 parent beb0e1c commit bae2e61

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

csharp/0063-unique-paths-ii.cs

+22
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)