Skip to content

Commit 836d3a2

Browse files
committed
Unique Paths
1 parent cd5c7ae commit 836d3a2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

unique-paths/TonyKim9401.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// TC: O (m * n)
2+
// SC: O (m * n)
3+
// -> need to retrieve all elements
4+
class Solution {
5+
public int uniquePaths(int m, int n) {
6+
int[][] dp = new int[m][n];
7+
8+
for (int i = 0; i < m; i++) dp[i][0] = 1;
9+
for (int j = 0; j < n; j++) dp[0][j] = 1;
10+
11+
for (int i = 1; i < m; i++) {
12+
for (int j = 1; j < n; j++) {
13+
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
14+
}
15+
}
16+
return dp[m-1][n-1];
17+
}
18+
}

0 commit comments

Comments
 (0)