Replaced for loop with enhanced for
This commit is contained in:
parent
4a45d8c808
commit
caadf4ceb4
|
@ -10,8 +10,8 @@ class Trie {
|
||||||
void insert(String word) {
|
void insert(String word) {
|
||||||
TrieNode current = root;
|
TrieNode current = root;
|
||||||
|
|
||||||
for (int i = 0; i < word.length(); i++) {
|
for (char l : word.toCharArray()) {
|
||||||
current = current.getChildren().computeIfAbsent(word.charAt(i), c -> new TrieNode());
|
current = current.getChildren().computeIfAbsent(l, c -> new TrieNode());
|
||||||
}
|
}
|
||||||
current.setEndOfWord(true);
|
current.setEndOfWord(true);
|
||||||
}
|
}
|
||||||
|
@ -59,4 +59,4 @@ class Trie {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue