Skip to content

Commit 0276071

Browse files
BarklimBarklim
Barklim
authored and
Barklim
committed
add tries examples
1 parent 521ec62 commit 0276071

File tree

5 files changed

+94
-1
lines changed

5 files changed

+94
-1
lines changed

example/7.Tries/0208.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
var Trie = function() {
3+
4+
};
5+
6+
/**
7+
* @param {string} word
8+
* @return {void}
9+
*/
10+
Trie.prototype.insert = function(word) {
11+
12+
};
13+
14+
/**
15+
* @param {string} word
16+
* @return {boolean}
17+
*/
18+
Trie.prototype.search = function(word) {
19+
20+
};
21+
22+
/**
23+
* @param {string} prefix
24+
* @return {boolean}
25+
*/
26+
Trie.prototype.startsWith = function(prefix) {
27+
28+
};
29+
30+
/**
31+
* Your Trie object will be instantiated and called as such:
32+
* var obj = new Trie()
33+
* obj.insert(word)
34+
* var param_2 = obj.search(word)
35+
* var param_3 = obj.startsWith(prefix)
36+
*/

example/7.Tries/0211.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
var WordDictionary = function() {
3+
4+
};
5+
6+
/**
7+
* @param {string} word
8+
* @return {void}
9+
*/
10+
WordDictionary.prototype.addWord = function(word) {
11+
12+
};
13+
14+
/**
15+
* @param {string} word
16+
* @return {boolean}
17+
*/
18+
WordDictionary.prototype.search = function(word) {
19+
20+
};
21+
22+
/**
23+
* Your WordDictionary object will be instantiated and called as such:
24+
* var obj = new WordDictionary()
25+
* obj.addWord(word)
26+
* var param_2 = obj.search(word)
27+
*/

example/7.Tries/0212.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {character[][]} board
3+
* @param {string[]} words
4+
* @return {string[]}
5+
*/
6+
var findWords = function(board, words) {
7+
8+
};
9+
10+
const example1 = suggestedProducts([["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], ["oath","pea","eat","rain"]); // ["eat","oath"]
11+
const example2 = suggestedProducts([["a","b"],["c","d"]], ["abcb"]); // []
12+
13+
console.log(example1);
14+
console.log(example2);
15+

example/7.Tries/1268.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {string[]} products
3+
* @param {string} searchWord
4+
* @return {string[][]}
5+
*/
6+
var suggestedProducts = function(products, searchWord) {
7+
8+
};
9+
10+
const example1 = suggestedProducts(["mobile","mouse","moneypot","monitor","mousepad"], "mouse"); // [["mobile","moneypot","monitor"],["mobile","moneypot","monitor"],["mouse","mousepad"],["mouse","mousepad"],["mouse","mousepad"]]
11+
const example2 = suggestedProducts(["havana"], "havana"); // [["havana"],["havana"],["havana"],["havana"],["havana"],["havana"]]
12+
13+
console.log(example1);
14+
console.log(example2);
15+

example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Better order to solve problems
134134
124. Binary Tree Maximum Path Sum
135135
297. Serialize and Deserialize Binary Tree
136136

137-
### Trie, Autocomplete
137+
### [Trie, Autocomplete](https://github.com/Barklim/leetcode-javascript/tree/master/example/7.Tries)
138138

139139
208. Implement trie
140140
1268. Search suggestion system

0 commit comments

Comments
 (0)