Skip to content

Commit f5f6dcc

Browse files
committed
[level 2] Title: 게임 맵 최단거리, Time: 3.46 ms, Memory: 57.9 MB -BaekjoonHub
1 parent 48f2204 commit f5f6dcc

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

프로그래머스/2/1844. 게임 맵 최단거리/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# [level 2] 게임 맵 최단거리 - 1844
22

3-
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/1844)
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/1844?language=java)
44

55
### 성능 요약
66

7-
메모리: 9.48 MB, 시간: 10.45 ms
7+
메모리: 57.9 MB, 시간: 3.46 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2025년 12월 31일 13:49:06
19+
2026년 05월 08일 19:53:54
2020

2121
### 문제 설명
2222

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int solution(int[][] maps) {
5+
int n = maps.length;
6+
int m = maps[0].length;
7+
boolean[][] visited = new boolean[n][m];
8+
9+
Queue<int[]> q = new LinkedList<>();
10+
q.add(new int[] {0, 0, 1});
11+
visited[0][0] = true;
12+
13+
int[] dx = {-1, 1, 0, 0};
14+
int[] dy = {0, 0, 1, -1};
15+
16+
while (!q.isEmpty()){
17+
int[] curr = q.poll();
18+
int x = curr[0];
19+
int y = curr[1];
20+
int dist = curr[2];
21+
22+
if (x == n-1 && y == m-1) return dist;
23+
24+
for (int i = 0; i< 4; i++){
25+
int nx = x + dx[i];
26+
int ny = y + dy[i];
27+
28+
if (nx >= 0 && nx < n && ny >= 0 && ny < m && maps[nx][ny] == 1 && !visited[nx][ny]){
29+
q.add(new int[] {nx, ny, dist+1});
30+
visited[nx][ny] = true;
31+
}
32+
}
33+
}
34+
return -1;
35+
}
36+
}

0 commit comments

Comments
 (0)