Created
July 17, 2022 22:15
-
-
Save RakhmedovRS/b460db4fd040a47ca33e8afc401af7c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Inserts a word into the trie. | |
| */ | |
| public void insert(String word) | |
| { | |
| TrieNode current = root; | |
| for (char ch : word.toCharArray()) | |
| { | |
| int pos = ch - 'a'; | |
| current.chars[pos] = true; | |
| TrieNode next = current.children[pos]; | |
| if (next == null) | |
| { | |
| current.children[pos] = new TrieNode(); | |
| next = current.children[pos]; | |
| } | |
| current = next; | |
| } | |
| current.isEnd = true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment