10000 Fixes bug where removal method was not working properly for cases whe… · codee/swift-algorithm-club@ed3a321 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed3a321

Browse files
committed
Fixes bug where removal method was not working properly for cases where the word to be removed has no children for it's last node.
1 parent 24b721a commit ed3a321

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

Trie/Trie.playground/Sources/Trie.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,8 @@ public extension Trie {
7373
currentNode.isTerminating = false
7474
} else {
7575
var character = currentNode.value
76-
while currentNode.children.count == 0, let parent = currentNode.parent, !parent.isTerminating {
77-
currentNode = parent
78-
currentNode.children[character!] = nil
79-
character = currentNode.value
80-
}
76+
currentNode.parent?.children[character!] = nil
77+
character = currentNode.value
8178
}
8279
}
8380
}

0 commit comments

Comments
 (0)
0