Skip to content

Commit b1ceace

Browse files
committed
feat: add swift solution 2 implementation to lcof2 problem: No.098
1 parent dd4898a commit b1ceace

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lcof2/剑指 Offer II 098. 路径的数目/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,24 @@ var uniquePaths = function (m, n) {
362362
};
363363
```
364364

365+
#### Swift
366+
367+
```swift
368+
class Solution {
369+
func uniquePaths(_ m: Int, _ n: Int) -> Int {
370+
var dp = Array(repeating: Array(repeating: 1, count: n), count: m)
371+
372+
for i in 1..<m {
373+
for j in 1..<n {
374+
dp[i][j] = dp[i-1][j] + dp[i][j-1]
375+
}
376+
}
377+
378+
return dp[m-1][n-1]
379+
}
380+
}
381+
```
382+
365383
<!-- tabs:end -->
366384

367385
<!-- solution:end -->
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
func uniquePaths(_ m: Int, _ n: Int) -> Int {
3+
var dp = Array(repeating: Array(repeating: 1, count: n), count: m)
4+
5+
for i in 1..<m {
6+
for j in 1..<n {
7+
dp[i][j] = dp[i-1][j] + dp[i][j-1]
8+
}
9+
}
10+
11+
return dp[m-1][n-1]
12+
}
13+
}

0 commit comments

Comments
 (0)