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

Lines changed: 22 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy