[C++] νΈλΌμ΄(Trie)
Β·
π Computer Science/β Algorithm
νΈλΌμ΄(Trie) μ¬λ¬ λ¬Έμμ΄μ ν¨μ¨μ μΌλ‘ μ μ₯νκ³ νμνκΈ° μν νΈλ¦¬ ννμ μλ£κ΅¬μ‘°λ‘ μκ° λ³΅μ‘λλ O(n)μ΄λ€. κΈ°λ³Έ μ리 struct Trie{ Trie* next[26]; bool finish; Trie() :finish(false) { for (int i = 0; i insert(key + 1); } bool find(const char* key) { if (*key == 0) return finish; int curr = *key - 'a'; if (next[curr] != NULL) return next[curr]->find(key + 1); return false; }}; λ¬Έμ https://www.acmicpc.net/problem/5670 5670λ²: ν΄λν° μνν΄λ..