Skip to content

Commit 282433f

Browse files
committed
Unique Paths
1 parent 063a924 commit 282433f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

unique-paths/forest000014.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Time Complexity: O(m * n)
3+
Space Complexity: O(m * n)
4+
*/
5+
class Solution {
6+
public int uniquePaths(int m, int n) {
7+
int[][] dp = new int[m][n];
8+
9+
for (int i = 0; i < n; i++) {
10+
dp[0][i] = 1;
11+
}
12+
for (int i = 1; i < m; i++) {
13+
dp[i][0] = 1;
14+
for (int j = 1; j < n; j++) {
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)