File tree Expand file tree Collapse file tree 2 files changed +6
-0
lines changed
src/_DataStructures_/Trees/Trie Expand file tree Collapse file tree 2 files changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ class TrieNode {
33 this . char = char ;
44 this . children = [ ] ;
55 this . isEndOfWord = false ;
6+ this . wordCount = 0 ;
67
78 // mark all the alphabets as null
89 for ( let i = 0 ; i < 26 ; i += 1 ) this . children [ i ] = null ;
@@ -15,6 +16,10 @@ class TrieNode {
1516 unmarkAsLeaf ( ) {
1617 this . isEndOfWord = false ;
1718 }
19+
20+ increaseCount ( ) {
21+ this . wordCount += 1 ;
22+ }
1823}
1924
2025module . exports = TrieNode ;
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ class Trie {
3232 // when we are done with inserting all the character of the word,
3333 // mark the node as end leaf
3434 currentNode . markAsLeaf ( ) ;
35+ currentNode . increaseCount ( ) ;
3536 return true ;
3637 }
3738
You can’t perform that action at this time.
0 commit comments