We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 481a307 commit 772a0e1Copy full SHA for 772a0e1
1 file changed
src/data_structures/trie.rs
@@ -45,7 +45,7 @@ impl Trie {
45
pub fn insert(&mut self, s: &[char]) {
46
let mut v = 0;
47
for &ch in s {
48
- let idx = (ch as u8 - FIRST_CHAR as u8) as usize;
+ let idx = ch as usize - FIRST_CHAR as usize;
49
if self.t[v].next[idx].is_none() {
50
self.t[v].next[idx] = Some(self.t.len());
51
self.t.push(Node::default());
@@ -63,11 +63,12 @@ impl Trie {
63
pub fn find(&self, s: &[char]) -> usize {
64
65
66
67
- if self.t[v].next[idx].is_none() {
+ if let Some(u) = self.t[v].next[idx] {
68
+ v = u;
69
+ } else {
70
return 0;
71
}
- v = self.t[v].next[idx].unwrap();
72
73
self.t[v].cnt_words
74
0 commit comments