We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
package main.java.com.poogle.PG.Q43163; public class Solution { static int answer; static boolean[] visited; public static void main(String[] args) { System.out.println(solution("hit", "cog", new String[]{"hot", "dot", "dog", "lot", "log", "cog"})); System.out.println(solution("hit", "cog", new String[]{"hot", "dot", "dog", "lot", "log"})); } public static int solution(String begin, String target, String[] words) { answer = 51; visited = new boolean[51]; dfs(begin, target, words, 0); return answer == 51 ? 0 : answer; } private static void dfs(String begin, String target, String[] words, int cnt) { if (begin.equals(target)) { answer = Math.min(answer, cnt); return; } for (int i = 0; i < words.length; i++) { if (!visited[i] && check(begin, words[i])) { visited[i] = true; dfs(words[i], target, words, cnt + 1); visited[i] = false; } } } private static boolean check(String begin, String word) { int cnt = 0; for (int j = 0; j < begin.length(); j++) { if (begin.charAt(j) != word.charAt(j)) cnt++; } return cnt == 1; } }
The text was updated successfully, but these errors were encountered:
suhyunsim
No branches or pull requests
문제
핵심 아이디어
어려운 점, 실수
풀이
The text was updated successfully, but these errors were encountered: