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 a3a57e2 commit 4fae071Copy full SHA for 4fae071
Trie/Trie_add_Search_using_dict.py
@@ -0,0 +1,32 @@
1
+class Trie:
2
+ root = {}
3
+
4
+ def add(self, word):
5
+ cur = self.root
6
7
+ for ch in word:
8
+ if ch not in cur:
9
+ cur[ch] = {}
10
+ cur = cur[ch]
11
+ cur['*'] = True
12
13
+ def search(self,word):
14
15
16
17
18
+ return False
19
20
+ if '*' in cur:
21
+ return True
22
+ else:
23
24
+dictionary = Trie()
25
+dictionary.add("pqr")
26
+dictionary.add("pqrst")
27
+print(dictionary.search("pqr"))
28
+print(dictionary.search("pq"))
29
+print(dictionary.search("p"))
30
+print(dictionary.search("pqrst"))
31
+dictionary.add("p")
32
0 commit comments