Replaced for loop with enhanced for

This commit is contained in:
John Richardson 2020-04-26 13:17:19 +02:00 committed by GitHub
parent 4a45d8c808
commit caadf4ceb4
1 changed files with 3 additions and 3 deletions

View File

@ -10,8 +10,8 @@ class Trie {
void insert(String word) {
TrieNode current = root;
for (int i = 0; i < word.length(); i++) {
current = current.getChildren().computeIfAbsent(word.charAt(i), c -> new TrieNode());
for (char l : word.toCharArray()) {
current = current.getChildren().computeIfAbsent(l, c -> new TrieNode());
}
current.setEndOfWord(true);
}
@ -59,4 +59,4 @@ class Trie {
}
return false;
}
}
}