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 39b3942 commit 615fffbCopy full SHA for 615fffb
1 file changed
implement-trie-prefix-tree/okyungjin.py
@@ -0,0 +1,26 @@
1
+class Trie:
2
+
3
+ def __init__(self):
4
+ self.word_set = set()
5
+ self.prefix_set = set()
6
7
8
+ def insert(self, word: str) -> None:
9
+ if word in self.word_set:
10
+ return
11
12
+ self.word_set.add(word)
13
14
+ prefix = ''
15
+ for char in word:
16
+ prefix += char
17
+ self.prefix_set.add(prefix)
18
19
20
+ def search(self, word: str) -> bool:
21
+ return word in self.word_set
22
23
24
+ def startsWith(self, prefix: str) -> bool:
25
+ return prefix in self.prefix_set
26
0 commit comments