feat(geektime_algo): add 35 trie fix get_or_insert_with error

This commit is contained in:
caitlin 2019-08-16 07:03:31 +08:00
parent dc4d17df22
commit 9803c0ca81

View File

@ -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;
} }