From 4065b1fba1f88ea951dc88d7013e1bdabb5f50e7 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Mon, 8 Sep 2025 23:42:39 +0900 Subject: [PATCH] =?UTF-8?q?[20250908]=20PGM=20/=20LV2=20/=20=EA=B2=8C?= =?UTF-8?q?=EC=9E=84=20=EB=A7=B5=20=EC=B5=9C=EB=8B=A8=EA=B1=B0=EB=A6=AC=20?= =?UTF-8?q?/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...34\353\213\250\352\261\260\353\246\254.md" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "suyeun84/202509/08 PGM LV2 \352\262\214\354\236\204 \353\247\265 \354\265\234\353\213\250\352\261\260\353\246\254.md" diff --git "a/suyeun84/202509/08 PGM LV2 \352\262\214\354\236\204 \353\247\265 \354\265\234\353\213\250\352\261\260\353\246\254.md" "b/suyeun84/202509/08 PGM LV2 \352\262\214\354\236\204 \353\247\265 \354\265\234\353\213\250\352\261\260\353\246\254.md" new file mode 100644 index 00000000..39d39de7 --- /dev/null +++ "b/suyeun84/202509/08 PGM LV2 \352\262\214\354\236\204 \353\247\265 \354\265\234\353\213\250\352\261\260\353\246\254.md" @@ -0,0 +1,34 @@ +```java +import java.util.*; +class Solution { + public int solution(int[][] maps) { + + return bfs(maps); + } + public int bfs(int[][] maps) { + int n = maps.length; + int m = maps[0].length; + int[][] d = new int[][]{{1,0}, {-1,0}, {0,1}, {0,-1}}; + int[][] visited = new int[n][m]; + Queue q = new LinkedList<>(); + q.add(new int[]{0, 0, 1}); + visited[0][0] = 1; + while (!q.isEmpty()) { + int[] curr = q.poll(); + for (int[] move : d) { + int ny = curr[0] + move[0]; + int nx = curr[1] + move[1]; + if (0 > ny || ny >= n || 0 > nx || nx >= m || maps[ny][nx] == 0 || visited[ny][nx] != 0) { + continue; + } + visited[ny][nx] = curr[2] + 1; + q.add(new int[]{ny, nx, curr[2]+1}); + if (ny == n-1 && nx == m-1) { + return visited[ny][nx]; + } + } + } + return -1; + } +} +```