File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed
Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ impl Trie {
4545 pub fn insert ( & mut self , s : & [ char ] ) {
4646 let mut v = 0 ;
4747 for & ch in s {
48- let idx = ( ch as u8 - FIRST_CHAR as u8 ) as usize ;
48+ let idx = ch as usize - FIRST_CHAR as usize ;
4949 if self . t [ v] . next [ idx] . is_none ( ) {
5050 self . t [ v] . next [ idx] = Some ( self . t . len ( ) ) ;
5151 self . t . push ( Node :: default ( ) ) ;
@@ -63,11 +63,12 @@ impl Trie {
6363 pub fn find ( & self , s : & [ char ] ) -> usize {
6464 let mut v = 0 ;
6565 for & ch in s {
66- let idx = ( ch as u8 - FIRST_CHAR as u8 ) as usize ;
67- if self . t [ v] . next [ idx] . is_none ( ) {
66+ let idx = ch as usize - FIRST_CHAR as usize ;
67+ if let Some ( u) = self . t [ v] . next [ idx] {
68+ v = u;
69+ } else {
6870 return 0 ;
6971 }
70- v = self . t [ v] . next [ idx] . unwrap ( ) ;
7172 }
7273 self . t [ v] . cnt_words
7374 }
You can’t perform that action at this time.
0 commit comments