File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,7 @@ def insertTrie(root,value):
32
32
insertTrie (root .children [i ],value [1 :])
33
33
34
34
def printTrie (root ,prefix ):
35
- if root .end :
36
- print (prefix )
35
+ print (prefix )
37
36
for i in range (62 ):
38
37
if root .children [i ] != None :
39
38
printTrie (root .children [i ],prefix + getchr (i ))
@@ -47,12 +46,23 @@ def searchTrie(root,value):
47
46
return False
48
47
return searchTrie (root .children [i ], value [1 :])
49
48
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
50
59
51
60
def solution (input ):
52
61
root = TrieNode ()
53
62
insertTrie (root ,"aa" )
54
63
insertTrie (root ,"ab" )
55
64
insertTrie (root ,"acd" )
56
- insertTrie (root ,"123Aa" )
65
+ insertTrie (root ,"cd" )
66
+ deleteTrie (root ,"aa" )
57
67
printTrie (root ,"" )
58
68
print (searchTrie (root ,"aaz" ))
You can’t perform that action at this time.
0 commit comments