Skip to content

Commit b354bd2

Browse files
donghyeon95donghyeon95
authored andcommitted
feat: Unique Paths #273
1 parent 916cfe1 commit b354bd2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

unique-paths/donghyeon95.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java.util.Arrays;
2+
3+
class Solution {
4+
public int uniquePaths(int m, int n) {
5+
// f(x,y) = f(x-1, y) + f(x, y-1)
6+
int[][] dp = new int[m][n];
7+
Arrays.fill(dp[0], 1);
8+
for (int i=0; i<m; i++) {
9+
dp[i][0] = 1;
10+
}
11+
12+
for (int i=1; i<m; i++) {
13+
for (int j=1; j<n; j++) {
14+
dp[i][j] = dp[i-1][j] + dp[i][j-1];
15+
}
16+
}
17+
18+
return dp[m - 1][n - 1];
19+
}
20+
}

0 commit comments

Comments
 (0)