題目會給定兩個輸入。
第一個輸入是關鍵字清單products,第二個是使用者輸入的字串searchWord。
要求我們實現關鍵字搜尋建議系統,使用者每輸入一個字元就推薦一次。
推薦時,優先返回字典序(Lecial order)最接近的關鍵字,最多不要超過三個關鍵字。
Example 1:
Input:
products = ["mobile","mouse","moneypot","monitor","mousepad"], searchWord = "mouse"
Output:
[
["mobile","moneypot","monitor"], # 使用者輸入m
["mobile","moneypot","monitor"], # 使用者輸入mo
["mouse","mousepad"], # 使用者輸入mou
["mouse","mousepad"], # 使用者輸入mous
["mouse","mousepad"] # 使用者輸入mouse
]
Explanation: products sorted lexicographically = ["mobile","moneypot","monitor","mouse","mousepad"].
After typing m and mo all products match and we show user ["mobile","moneypot","monitor"].
After typing mou, mous and mouse the system suggests ["mouse","mousepad"].
Example 2:
Input: products = ["havana"], searchWord = "havana"
Output: [["havana"],["havana"],["havana"],["havana"],["havana"],["havana"]]
Explanation: The only word "havana" will be always suggested while typing the search word.
Constraints:
1 <= products.length <= 1000
關鍵字清單products 陣列長度介於1~1000。
1 <= products[i].length <= 3000
每個關鍵字長度介於1~3000。
1 <= sum(products[i].length) <= 2 * 10^4
關鍵字總長度介於1~兩萬之間。
products
are unique.所有關鍵字清單裡的關鍵字都是獨一無二的,不會重複。
products[i]
consists of lowercase English letters.關鍵字都只會有小寫英文字母。
1 <= searchWord.length <= 1000
使用者輸入的字串介於1~1000個字元之間。
searchWord
consists of lowercase English letters.使用者的輸入只會有小寫英文字母。