Last active
September 17, 2022 15:30
-
-
Save 1gravity/e5242b3df0ce27735e735ba28a7c158e to your computer and use it in GitHub Desktop.
Kotlin Trie Insert Basic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun insert(key: String, value: Value) { | |
var currentNode = root | |
for (char in key) { | |
if (currentNode.children[char] == null) { | |
currentNode.children[char] = Node() | |
} | |
currentNode = currentNode.children[char]!! | |
} | |
currentNode.value = value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment