From 5a81559ead18857e735a4b7871a02eab9f869675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=8B=A0=EC=A7=80?= <101992179+ksinji@users.noreply.github.com> Date: Tue, 18 Nov 2025 23:00:58 +0900 Subject: [PATCH] =?UTF-8?q?[20251118]=20PGM=20/=20Lv3=20/=20=EB=8B=A8?= =?UTF-8?q?=EC=96=B4=20=EB=B3=80=ED=99=98=20/=20=EA=B0=95=EC=8B=A0?= =?UTF-8?q?=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\226\264 \353\263\200\355\231\230.md" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "ksinji/202511/18 PGM \353\213\250\354\226\264 \353\263\200\355\231\230.md" diff --git "a/ksinji/202511/18 PGM \353\213\250\354\226\264 \353\263\200\355\231\230.md" "b/ksinji/202511/18 PGM \353\213\250\354\226\264 \353\263\200\355\231\230.md" new file mode 100644 index 00000000..abcf1232 --- /dev/null +++ "b/ksinji/202511/18 PGM \353\213\250\354\226\264 \353\263\200\355\231\230.md" @@ -0,0 +1,41 @@ +```java +class Solution { + public boolean[] visited; + public int answer = 0; + + public int solution(String begin, String target, String[] words) { + visited = new boolean[words.length]; + dfs(begin, target, words, 0); + + return answer; + } + + public void dfs(String cur, String target, String[] words, int cnt) { + if (cur.equals(target)) { + answer = cnt; + return; + } + + for (int i = 0; i < words.length; i++) { + if (visited[i]) continue; + + if (canConvert(cur, words[i])) { + visited[i] = true; + dfs(words[i], target, words, cnt+1); + visited[i] = false; + } + } + } + + public boolean canConvert(String from, String to) { + int cnt = 0; + for (int i = 0; i < from.length(); i++) { + if (from.charAt(i) != to.charAt(i)) cnt++; + } + + if (cnt == 1) return true; + return false; + } + +} +```