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 d5b0c6b commit 356bccbCopy full SHA for 356bccb
1 file changed
unique-paths/ekgns33.java
@@ -0,0 +1,38 @@
1
+/*
2
+input : 2D matrix
3
+output : the number of possible unique paths
4
+constraints :
5
+1) range of m and n
6
+[1, 100]
7
+
8
+solution 1) dfs?
9
+move right or move down.
10
+tc : O(mn)
11
+sc : O(mn)
12
13
+solution 2) dp + tabulation
14
+let dp[i][j] the number of unique paths from starting point.
15
+ there are only 2 way to get coordinate i, j
16
+ 1) from i-1, j
17
+ 2) from i, j-1
18
+dp[i][j] = dp[i-1][j] + dp[i][j-1]
19
20
21
22
+ */
23
24
+class Solution {
25
+ public int uniquePaths(int m, int n) {
26
+ int[][] dp = new int[m][n];
27
+ for(int i = 0; i < m; i++) {
28
+ for(int j = 0; j < n; j++) {
29
+ if(i == 0 || j == 0) {
30
+ dp[i][j] = 1;
31
+ continue;
32
+ }
33
+ dp[i][j] = dp[i][j-1] + dp[i-1][j];
34
35
36
+ return dp[m-1][n-1];
37
38
+}
0 commit comments