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) {
1414 final Trie trie = new Trie ();
1515 setOfStrings .forEach (trie ::insert );
1616 System .out .println (trie .query ("psst" ));
17+ System .out .println (trie .query ("psstq" ));
1718 trie .update ("qqrs" , "psst" );
1819 System .out .println (trie .query ("qqrs" ));
1920 System .out .println (trie .query ("psst" ));
@@ -30,10 +31,11 @@ public Trie() {
3031 public int query (final String s ) {
3132 TrieNode current = root ;
3233 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 ));
3739 }
3840 return current .terminating ;
3941 }
You can’t perform that action at this time.
0 commit comments