File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
src/main/java/main/java/videos Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ public static void main(String[] args) {
14
14
final Trie trie = new Trie ();
15
15
setOfStrings .forEach (trie ::insert );
16
16
System .out .println (trie .query ("psst" ));
17
+ System .out .println (trie .query ("psstq" ));
17
18
trie .update ("qqrs" , "psst" );
18
19
System .out .println (trie .query ("qqrs" ));
19
20
System .out .println (trie .query ("psst" ));
@@ -30,10 +31,11 @@ public Trie() {
30
31
public int query (final String s ) {
31
32
TrieNode current = root ;
32
33
for (int i = 0 ; i < s .length (); i ++) {
33
- if (current == null ) {
34
- return 0 ;
35
- }
36
- current = current .next (s .charAt (i ));
34
+ if (current ==null || current .next (s .charAt (i ))==null ) {
35
+ return 0 ;
36
+ }
37
+ else
38
+ current =current .next (s .charAt (i ));
37
39
}
38
40
return current .terminating ;
39
41
}
You can’t perform that action at this time.
0 commit comments