Skip to content

Commit c6b6660

Browse files
committed
add 62. Unique Paths
1 parent 81075df commit c6b6660

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

java/62-Unique-Paths.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public static int uniquePaths(int m, int n) {
3+
int[][] dp = new int[m][n];
4+
5+
// Fill out last row
6+
for (int j = 0; j < n; j++) {
7+
dp[m-1][j] = 1;
8+
}
9+
10+
// Fill out last column
11+
for (int i = 0; i < m; i++) {
12+
dp[i][n-1] = 1;
13+
}
14+
15+
for (int i = m - 2; i >= 0; i--) {
16+
for (int j = n - 2; j >= 0; j--) {
17+
dp[i][j] = dp[i][j + 1] + dp[i + 1][j];
18+
}
19+
}
20+
return dp[0][0];
21+
}
22+
}

0 commit comments

Comments
 (0)