Skip to content

Commit 32faa56

Browse files
committed
Solution Unique paths
1 parent 1c02235 commit 32faa56

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

unique-paths/doitduri.swift

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

0 commit comments

Comments
 (0)