Skip to content

feat: add swift solution 2 implementation to lcof2 problem: No.098 #3504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lcof2/剑指 Offer II 098. 路径的数目/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,24 @@ var uniquePaths = function (m, n) {
};
```

#### Swift

```swift
class Solution {
func uniquePaths(_ m: Int, _ n: Int) -> Int {
var dp = Array(repeating: Array(repeating: 1, count: n), count: m)

for i in 1..<m {
for j in 1..<n {
dp[i][j] = dp[i-1][j] + dp[i][j-1]
}
}

return dp[m-1][n-1]
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
13 changes: 13 additions & 0 deletions lcof2/剑指 Offer II 098. 路径的数目/Solution2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution {
func uniquePaths(_ m: Int, _ n: Int) -> Int {
var dp = Array(repeating: Array(repeating: 1, count: n), count: m)

for i in 1..<m {
for j in 1..<n {
dp[i][j] = dp[i-1][j] + dp[i][j-1]
}
}

return dp[m-1][n-1]
}
}
Loading