2023-12-09 18:42:21 +08:00
< p > Design a special dictionary that searches the words in it by a prefix and a suffix.< / p >
2022-03-27 20:46:41 +08:00
< p > Implement the < code > WordFilter< / code > class:< / p >
< ul >
< li > < code > WordFilter(string[] words)< / code > Initializes the object with the < code > words< / code > in the dictionary.< / li >
2023-12-09 18:42:21 +08:00
< li > < code > f(string pref, string suff)< / code > Returns < em > the index of the word in the dictionary,< / em > which has the prefix < code > pref< / code > and the suffix < code > suff< / code > . If there is more than one valid index, return < strong > the largest< / strong > of them. If there is no such word in the dictionary, return < code > -1< / code > .< / li >
2022-03-27 20:46:41 +08:00
< / ul >
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-03-27 20:46:41 +08:00
< pre >
< strong > Input< / strong >
[" WordFilter" , " f" ]
[[[" apple" ]], [" a" , " e" ]]
< strong > Output< / strong >
[null, 0]
< strong > Explanation< / strong >
WordFilter wordFilter = new WordFilter([" apple" ]);
2023-12-09 18:42:21 +08:00
wordFilter.f(" a" , " e" ); // return 0, because the word at index 0 has prefix = " a" and suffix = " e" .
2022-03-27 20:46:41 +08:00
< / pre >
< p > < / p >
< p > < strong > Constraints:< / strong > < / p >
< ul >
2023-12-09 18:42:21 +08:00
< li > < code > 1 < = words.length < = 10< sup > 4< / sup > < / code > < / li >
< li > < code > 1 < = words[i].length < = 7< / code > < / li >
< li > < code > 1 < = pref.length, suff.length < = 7< / code > < / li >
< li > < code > words[i]< / code > , < code > pref< / code > and < code > suff< / code > consist of lowercase English letters only.< / li >
< li > At most < code > 10< sup > 4< / sup > < / code > calls will be made to the function < code > f< / code > .< / li >
2022-03-27 20:46:41 +08:00
< / ul >