Skip to content

Commit b3c0c94

Browse files
Sean PrashadSean Prashad
authored andcommitted
Add 62_Unique_Paths.java
1 parent 9b4baad commit b3c0c94

File tree

1 file changed

+21
-0
lines changed

1 file changed

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