Skip to content

Commit 95fc0c2

Browse files
committed
63_Unique_Paths_II
1 parent 48c72e7 commit 95fc0c2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ BFS, DFS, Dijkstra, Floyd–Warshall, Bellman-Ford, Kruskal, Prim's, Minimum Spa
775775
|59| **[1277. Count Square Submatrices with All Ones](https://tinyurl.com/y6a82a9r)** | [Python](https://tinyurl.com/wu6rdaw/1277_Count_Square_Submatrices_with_All_Ones.py), [Swift](https://tinyurl.com/wuja3c4/1277_Count_Square_Submatrices_with_All_Ones.swift)| [Must](https://tinyurl.com/y4sa8zgk) | Medium | --- |
776776
|60| [418. Sentence Screen Fitting](https://tinyurl.com/yhtu7lld) | [Swift](https://tinyurl.com/wuja3c4/418_Sentence_Screen_Fitting.swift)| [Art 1](https://tinyurl.com/yh4xt84c) | Medium | --- |
777777
|61| [1937. Maximum Number of Points with Cost](https://tinyurl.com/yhh6dmeh) | [Swift](https://tinyurl.com/wuja3c4/1937_Maximum_Number_of_Points_with_Cost.swift)| [Art 1](https://tinyurl.com/yg6hs4md) | Medium | --- |
778+
|61| [63. Unique Paths II](https://tinyurl.com/yjh69kzh) | [Swift](https://tinyurl.com/wuja3c4/63_Unique_Paths_II.swift)| --- | Medium | --- |
778779

779780

780781

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
func uniquePathsWithObstacles(_ obstacleGrid: [[Int]]) -> Int {
3+
var dp = Array(repeating: Array(repeating: 0, count: obstacleGrid[0].count + 1), count: obstacleGrid.count + 1)
4+
for i in 0..<obstacleGrid.count {
5+
for j in 0..<obstacleGrid[0].count {
6+
if obstacleGrid[i][j] == 0 {
7+
if i == 0 && j == 0 {
8+
dp[i + 1][j + 1] = 1
9+
} else {
10+
dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j]
11+
}
12+
}
13+
}
14+
}
15+
return dp.last!.last!
16+
}
17+
}

0 commit comments

Comments
 (0)