Skip to content

Commit f4443eb

Browse files
author
eunhwa99
committed
unique paths
1 parent a48162d commit f4443eb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

unique-paths/eunhwa99.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
3+
public int uniquePaths(int m, int n) {
4+
int[][] paths = new int[m][n];
5+
6+
for (int i = 0; i < m; i++) {
7+
paths[i][0] = 1; //가장 왼쪽 줄은 항상 경로가 1개
8+
}
9+
10+
for (int i = 0; i < n; i++) {
11+
paths[0][i] = 1; // 가장 윗줄은 항상 경로가 1개
12+
}
13+
for (int i = 1; i < m; i++) {
14+
for (int j = 1; j < n; j++) {
15+
16+
paths[i][j] = paths[i - 1][j] + paths[i][j - 1];
17+
}
18+
}
19+
20+
return paths[m - 1][n - 1];
21+
}
22+
}

0 commit comments

Comments
 (0)