Skip to content

[4주차] 백제완 #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 6, 2024
Prev Previous commit
Next Next commit
백제완: [PG] 42898 등굣길_241003
  • Loading branch information
Jewan1120 committed Oct 3, 2024
commit e987d06eb0a208e165ea17ce61bafd9c72c9994d
19 changes: 19 additions & 0 deletions Programmers/Level3/JW_42898.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
final int MOD = 1_000_000_007; // 나머지 연산
public int solution(int m, int n, int[][] puddles) {
int[][] board = new int[n + 1][m + 1];
// 웅덩이가 있는 위치 표시
for (int[] puddle : puddles)
board[puddle[1]][puddle[0]] = -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 웅덩이가 있는 곳을 2차원 boolean 배열을 만들어서 저장해줬는데, 그냥 int형 배열에 모두 다 저장해줘도 됐군요,,,,👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

최대한 하나의 배열에서 끝내려고 -1로 표기했더니 계산도 간단해지고 괜찮더라구요!

board[0][1] = 1; // 시작 위치의 위 혹은 왼쪽을 1로 초기화
for (int i = 1; i < n + 1; i++)
for (int j = 1; j < m + 1; j++)
// 현재 위치가 웅덩이가 아니라면
if (board[i][j] != -1) {
int up = Math.max(0, board[i - 1][j]); // 위쪽에서 오는 경우
int lf = Math.max(0, board[i][j - 1]); // 왼쪽에서 오는 경우
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 최댓값으로 바로 받아와도 되는군요..!! 👍 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

최댓값으로 0과 함께 받아오면 체크해둔 -1을 무시할 수 있어요!

board[i][j] = (up + lf) % MOD; // 가능한 경우의 수 계산
}
return board[n][m];
}
}