mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
53 lines
2.8 KiB
HTML
53 lines
2.8 KiB
HTML
<p>给你一个产品数组 <code>products</code> 和一个字符串 <code>searchWord</code> ,<code>products</code> 数组中每个产品都是一个字符串。</p>
|
||
|
||
<p>请你设计一个推荐系统,在依次输入单词 <code>searchWord</code> 的每一个字母后,推荐 <code>products</code> 数组中前缀与 <code>searchWord</code> 相同的最多三个产品。如果前缀相同的可推荐产品超过三个,请按字典序返回最小的三个。</p>
|
||
|
||
<p>请你以二维列表的形式,返回在输入 <code>searchWord</code> 每个字母后相应的推荐产品的列表。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>products = ["mobile","mouse","moneypot","monitor","mousepad"], searchWord = "mouse"
|
||
<strong>输出:</strong>[
|
||
["mobile","moneypot","monitor"],
|
||
["mobile","moneypot","monitor"],
|
||
["mouse","mousepad"],
|
||
["mouse","mousepad"],
|
||
["mouse","mousepad"]
|
||
]
|
||
<strong>解释:</strong>按字典序排序后的产品列表是 ["mobile","moneypot","monitor","mouse","mousepad"]
|
||
输入 m 和 mo,由于所有产品的前缀都相同,所以系统返回字典序最小的三个产品 ["mobile","moneypot","monitor"]
|
||
输入 mou, mous 和 mouse 后系统都返回 ["mouse","mousepad"]
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>products = ["havana"], searchWord = "havana"
|
||
<strong>输出:</strong>[["havana"],["havana"],["havana"],["havana"],["havana"],["havana"]]
|
||
</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>products = ["bags","baggage","banner","box","cloths"], searchWord = "bags"
|
||
<strong>输出:</strong>[["baggage","bags","banner"],["baggage","bags","banner"],["baggage","bags"],["bags"]]
|
||
</pre>
|
||
|
||
<p><strong>示例 4:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>products = ["havana"], searchWord = "tatiana"
|
||
<strong>输出:</strong>[[],[],[],[],[],[],[]]
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= products.length <= 1000</code></li>
|
||
<li><code>1 <= Σ products[i].length <= 2 * 10^4</code></li>
|
||
<li><code>products[i]</code> 中所有的字符都是小写英文字母。</li>
|
||
<li><code>1 <= searchWord.length <= 1000</code></li>
|
||
<li><code>searchWord</code> 中所有字符都是小写英文字母。</li>
|
||
</ul>
|