Skip to content

Commit d2abbfa

Browse files
committed
Runtime: 278 ms (Top 63.18%) | Memory: 65.8 MB (Top 36.92%)
1 parent b90c7a4 commit d2abbfa

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
// Runtime: 278 ms (Top 63.18%) | Memory: 65.8 MB (Top 36.92%)
12

23
var Trie = function() {
34
this.children = {};
45
this.word = false;
56
};
67

7-
/**
8+
/**
89
* @param {string} word
910
* @return {void}
1011
*/
@@ -15,14 +16,14 @@ Trie.prototype.insert = function(word) {
1516
}
1617
let head = word[0];
1718
let tail = word.substring(1);
18-
19+
1920
if (!this.children[head]) {
2021
this.children[head] = new Trie();
2122
}
2223
this.children[head].insert(tail);
2324
};
2425

25-
/**
26+
/**
2627
* @param {string} word
2728
* @return {boolean}
2829
*/
@@ -36,34 +37,34 @@ Trie.prototype._search = function(word, method) {
3637
}
3738
let head = word[0];
3839
let tail = word.substring(1);
39-
40+
4041
if (!this.children[head]) {
4142
return false;
4243
}
43-
44+
4445
return this.children[head][method](tail);
4546
};
4647

47-
/**
48+
/**
4849
* @param {string} word
4950
* @return {boolean}
5051
*/
5152
Trie.prototype.search = function(word) {
5253
return this._search(word, 'search');
5354
};
5455

55-
/**
56+
/**
5657
* @param {string} prefix
5758
* @return {boolean}
5859
*/
5960
Trie.prototype.startsWith = function(prefix) {
6061
return this._search(prefix, 'startsWith');
6162
};
6263

63-
/**
64+
/**
6465
* Your Trie object will be instantiated and called as such:
6566
* var obj = new Trie()
6667
* obj.insert(word)
6768
* var param_2 = obj.search(word)
6869
* var param_3 = obj.startsWith(prefix)
69-
*/
70+
*/

0 commit comments

Comments
 (0)