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 804021b commit b161479Copy full SHA for b161479
Implement Trie (Prefix Tree) - Leetcode 208.py
@@ -0,0 +1,36 @@
1
+class Trie:
2
+ def __init__(self):
3
+ self.trie = {}
4
+
5
+ def insert(self, word: str) -> None:
6
+ d = self.trie
7
8
+ for c in word:
9
+ if c not in d:
10
+ d[c] = {}
11
+ d = d[c]
12
13
+ d['.'] = '.'
14
15
+ def search(self, word: str) -> bool:
16
17
18
19
20
+ return False
21
22
23
+ return '.' in d
24
25
+ def startsWith(self, prefix: str) -> bool:
26
27
28
+ for c in prefix:
29
30
31
32
33
+ return True
34
35
+ # Time: O(N) where N is the length of any string
36
+ # Space: O(T) where T is the total number of stored characters
0 commit comments