Skip to content

Commit

Permalink
unique paths
Browse files Browse the repository at this point in the history
  • Loading branch information
eunhwa99 committed Jan 18, 2025
1 parent a48162d commit f4443eb
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions unique-paths/eunhwa99.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {

public int uniquePaths(int m, int n) {
int[][] paths = new int[m][n];

for (int i = 0; i < m; i++) {
paths[i][0] = 1; //가장 왼쪽 줄은 항상 경로가 1개
}

for (int i = 0; i < n; i++) {
paths[0][i] = 1; // 가장 윗줄은 항상 경로가 1개
}
for (int i = 1; i < m; i++) {
for (int j = 1; j < n; j++) {

paths[i][j] = paths[i - 1][j] + paths[i][j - 1];
}
}

return paths[m - 1][n - 1];
}
}

0 comments on commit f4443eb

Please sign in to comment.