We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9303509 commit 2c80b43Copy full SHA for 2c80b43
MEDIUM/src/medium/UniquePaths.java
@@ -31,6 +31,18 @@ public int uniquePaths(int m, int n) {
31
return dp[m-1][n-1];
32
}
33
34
+ //and we can actually put the two initialization for loop into the one
35
+ public int uniquePaths_merged_for_loop(int m, int n) {
36
+ int[][] dp = new int[m][n];
37
+ for(int i = 0; i < m; i++){
38
+ for(int j = 0; j < n; j++){
39
+ if(i == 0 || j == 0) dp[i][j] = 0;
40
+ else dp[i][j] = dp[i-1][j] + dp[i][j-1];
41
+ }
42
43
+ return dp[m-1][n-1];
44
45
+
46
public static void main(String...strings){
47
UniquePaths test = new UniquePaths();
48
int m = 1;
0 commit comments