Skip to content

Commit d526f5d

Browse files
committed
feat: UniquePath problem solve with DynamicProgramming (DP)
1 parent 8bf046c commit d526f5d

File tree

1 file changed

+35
-0
lines changed
  • src/main/java/com/hyeonah/studyjava/algorithm/top50coding/dynamicprogramming

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.hyeonah.studyjava.algorithm.top50coding.dynamicprogramming;
2+
3+
/**
4+
* Created by hyeonahlee on 2021-01-31.
5+
*/
6+
public class UniquePaths {
7+
8+
public static void main(String[] args) {
9+
int m = 7;
10+
int n = 3;
11+
System.out.println(uniquePaths(m, n));
12+
}
13+
14+
private static int uniquePaths(int m, int n) {
15+
Integer[][] map = new Integer[m][n];
16+
17+
// 첫번째 행 1로 초기 셋팅
18+
for (int i = 0; i < m; i++) {
19+
map[i][0] = 1;
20+
}
21+
22+
// 첫번째 열 1로 초기 셋팅
23+
for (int i = 0; i < n; i++) {
24+
map[0][i] = 1;
25+
}
26+
27+
for (int i = 1; i < m; i++) {
28+
for (int j = 1; j < n; j++) {
29+
map[i][j] = map[i - 1][j] + map[i][j - 1];
30+
}
31+
}
32+
33+
return map[m - 1][n - 1];
34+
}
35+
}

0 commit comments

Comments
 (0)