We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 70bc661 commit e987dbaCopy full SHA for e987dba
implement-trie-prefix-tree/hyogshin.py
@@ -1,3 +1,16 @@
1
+"""
2
+풀이 방법
3
+- insert: 입력된 단어의 캐릭터로 for loop을 돌아 node.children에 없는 캐릭터라면 추가하고 있다면 node.isEnd = True
4
+- search: 입력된 단어를 캐릭터 단위로 for loop을 돌고 node.children에 없다면 바로 False 반환, 만약 모든 캐릭터가 있는 경우 단어있는 확인하기 위해 isEnd 체크
5
+- startsWith: 입력된 prefix로 for loop을 돌아 node.children에 없다면 바로 False 반환
6
+
7
+시간 복잡도: O(n)
8
+- for loop -> O(n)
9
10
+공간 복잡도: O(n)
11
+- Trie를 저장하는 공간 -> O(n)
12
13
14
from typing import List
15
16
class TrieNode:
@@ -57,3 +70,4 @@ def startsWith(self, prefix: str) -> bool:
57
70
print(trie.search("bat")) # True
58
71
print(trie.startsWith("ba")) # True
59
72
print(trie.search("bad")) # False
73
0 commit comments