Skip to content

Commit 9597693

Browse files
committed
Update Trie
1 parent caaf609 commit 9597693

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

learn/tree/day4/part1.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def insertTrie(root,value):
3232
insertTrie(root.children[i],value[1:])
3333

3434
def printTrie(root,prefix):
35-
if root.end:
36-
print(prefix)
35+
print(prefix)
3736
for i in range(62):
3837
if root.children[i] != None:
3938
printTrie(root.children[i],prefix+getchr(i))
@@ -47,12 +46,23 @@ def searchTrie(root,value):
4746
return False
4847
return searchTrie(root.children[i], value[1:])
4948

49+
def deleteTrie(root,value):
50+
if value == "":
51+
root.end = False
52+
else:
53+
i = getindex(value[0])
54+
root.children[i] = deleteTrie(root.children[i],value[1:])
55+
56+
if any(root.children):
57+
return root
58+
return None
5059

5160
def solution(input):
5261
root = TrieNode()
5362
insertTrie(root,"aa")
5463
insertTrie(root,"ab")
5564
insertTrie(root,"acd")
56-
insertTrie(root,"123Aa")
65+
insertTrie(root,"cd")
66+
deleteTrie(root,"aa")
5767
printTrie(root,"")
5868
print(searchTrie(root,"aaz"))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy