We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cd5c7ae commit 836d3a2Copy full SHA for 836d3a2
unique-paths/TonyKim9401.java
@@ -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