Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a6b3ce7

Browse files
committed
update: counting word ocurences
1 parent 6469d5f commit a6b3ce7

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

‎src/_DataStructures_/Trees/Trie/Node.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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

2025
module.exports = TrieNode;

‎src/_DataStructures_/Trees/Trie/index.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /