Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9533ecc

Browse filesBrowse files
authored
merge: HanJaehee Programmers 42898 등굣길
HanJaehee Programmers 42898 등굣길
2 parents e46b446 + 9e906fd commit 9533ecc
Copy full SHA for 9533ecc

File tree

Expand file treeCollapse file tree

2 files changed

+74
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+74
-0
lines changed
Open diff view settings
Collapse file
+48Lines changed: 48 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# 프로그래머스 42898 등굣길
2+
3+
[문제 링크](https://programmers.co.kr/learn/courses/30/lessons/42898)
4+
5+
## 1. 설계 로직
6+
7+
1. 초등학교 수학시간에 배웠던 최단경로 구하는 방법을 그대로 사용했다.
8+
2. 원래는 집을 기준으로 X축 벽, Y축 벽에 1을 채워넣는 방법이지만, 연산 편의를 위해 집에만 1을 넣어두고 시작
9+
3. 2중 for문 중 한 지점에서 위의 값, 왼쪽 값을 더한다. 그 지점의 값이 -1(웅덩이)라면, 0을 삽입하고 다음 연산으로
10+
4. 최종적으로 학교 위치인 m-1, n-1의 값을 출력한다.
11+
5. 각 연산에 % 연산을 하지 않으면 효율성 오류가 난다..
12+
13+
- 시간복잡도 : N^2
14+
15+
## 2. 코드
16+
17+
```java
18+
class Solution {
19+
public int solution(int m, int n, int[][] puddles) {
20+
int[][] map = new int[n][m];
21+
22+
for (int[] puddle : puddles)
23+
map[puddle[1] - 1][puddle[0] - 1] = -1;
24+
25+
map[0][0] = 1;
26+
27+
for (int i = 0; i < n; i++) {
28+
for (int j = 0; j < m; j++) {
29+
30+
if(map[i][j] == -1) {
31+
map[i][j] = 0;
32+
continue;
33+
}
34+
35+
if(i != 0) map[i][j] += map[i - 1][j] % 1000000007; // 이거 나머지 처리 안하면 효율성 못뚫음;
36+
if(j != 0) map[i][j] += map[i][j - 1] % 1000000007;
37+
}
38+
}
39+
40+
return map[n - 1][m - 1] % 1000000007;
41+
}
42+
43+
}
44+
```
45+
46+
## 3. 후기
47+
48+
- 착실하게 문제의 요구사항을 따라가면 되는 문제였습니다.
Collapse file
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
public int solution(int m, int n, int[][] puddles) {
3+
int[][] map = new int[n][m];
4+
5+
for (int[] puddle : puddles)
6+
map[puddle[1] - 1][puddle[0] - 1] = -1;
7+
8+
map[0][0] = 1;
9+
10+
for (int i = 0; i < n; i++) {
11+
for (int j = 0; j < m; j++) {
12+
13+
if(map[i][j] == -1) {
14+
map[i][j] = 0;
15+
continue;
16+
}
17+
18+
if(i != 0) map[i][j] += map[i - 1][j] % 1000000007; // 이거 나머지 처리 안하면 효율성 못뚫음;
19+
if(j != 0) map[i][j] += map[i][j - 1] % 1000000007;
20+
}
21+
}
22+
23+
return map[n - 1][m - 1] % 1000000007;
24+
}
25+
26+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.