자료구조 & 알고리즘/트라이

// 문자열 배열 strs 와 targets 가 주어졌을 때 // targets 내의 단어 중 한 문자만 바꾸면 strs 중의 단어가 되는지 판별하는 프로그램을 작성하세요. // 입출력 예시 // 입력 strs: "apple", "banana", "kiwi" // 입력 target: "applk", "bpple", "apple" // 출력: true, true, false public class Practice3 { public static void solution(String[] strs, String[] targets) { Practice2.Trie trie = new Practice2.Trie(); for (String s : strs) { trie.insert(s); } for (String ta..
class Node { Map child; //노드는 자식 Map과 터미널 여부를 갖고 있음.. boolean isTerminal; public Node() { this.child = new HashMap(); this.isTerminal = false; } } class Trie { Node head; public Trie() { this.head = new Node(); } public void insert(String data) { Node cur = this.head; for (int i = 0; i < data.length(); i++) { char c = data.charAt(i); cur.child.putIfAbsent(c, new Node()); cur = cur.child.get(c); ..
꾸준함의 미더덕
'자료구조 & 알고리즘/트라이' 카테고리의 글 목록