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 {
3
3
this . char = char ;
4
4
this . children = [ ] ;
5
5
this . isEndOfWord = false ;
6
+ this . wordCount = 0 ;
6
7
7
8
// mark all the alphabets as null
8
9
for ( let i = 0 ; i < 26 ; i += 1 ) this . children [ i ] = null ;
@@ -15,6 +16,10 @@ class TrieNode {
15
16
unmarkAsLeaf ( ) {
16
17
this . isEndOfWord = false ;
17
18
}
19
+
20
+ increaseCount ( ) {
21
+ this . wordCount += 1 ;
22
+ }
18
23
}
19
24
20
25
module . exports = TrieNode ;
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ class Trie {
32
32
// when we are done with inserting all the character of the word,
33
33
// mark the node as end leaf
34
34
currentNode . markAsLeaf ( ) ;
35
+ currentNode . increaseCount ( ) ;
35
36
return true ;
36
37
}
37
38
You can’t perform that action at this time.
0 commit comments