File tree Expand file tree Collapse file tree 1 file changed +2
-8
lines changed Expand file tree Collapse file tree 1 file changed +2
-8
lines changed Original file line number Diff line number Diff line change @@ -234,17 +234,14 @@ class TrieNode {
234234
235235class Trie {
236236 constructor () {
237- // The root node is an empty TrieNode.
238237 this .root = new TrieNode ();
239238 }
240239
241240 insert (word , node = this .root ) {
242241 const wordLength = word .length ;
243242 if (wordLength === 0 ) return ;
244243
245- // Iterate over each character in the word.
246244 for (let idx = 0 ; idx < wordLength; idx++ ) {
247- // Get the current character.
248245 let char = word[idx];
249246
250247 // Check if the current node has a child node for the current character.
@@ -255,12 +252,9 @@ class Trie {
255252
256253 // Move to the child node corresponding to the current character.
257254 node = node .children .get (char);
258-
259- // If this is the last character of the word, mark the node as the end of a word.
260- if (idx === word .length - 1 ) {
261- node .isEndOfWord = true ;
262- }
263255 }
256+
257+ node .isEndOfWord = true ;
264258 }
265259}
266260```
You can’t perform that action at this time.
0 commit comments