feat(geektime_algo): add 35 trie fix get_or_insert_with error
This commit is contained in:
parent
dc4d17df22
commit
9803c0ca81
@ -14,7 +14,7 @@ impl Trie {
|
|||||||
fn insert(&mut self, word: &str) {
|
fn insert(&mut self, word: &str) {
|
||||||
let mut curr = self;
|
let mut curr = self;
|
||||||
for i in word.chars().map(|c| (c as usize - 'a' as usize) as usize) {
|
for i in word.chars().map(|c| (c as usize - 'a' as usize) as usize) {
|
||||||
curr = curr.nodes[i].get_or_insert_with(Box::new(Trie::new()));
|
curr = curr.nodes[i].get_or_insert_with(|| Box::new(Trie::new()));
|
||||||
}
|
}
|
||||||
curr.is_ending = true;
|
curr.is_ending = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user