1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/添加与搜索单词 - 数据结构设计 [design-add-and-search-words-data-structure].html
2022-03-29 12:43:11 +08:00

43 lines
1.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>请你设计一个数据结构,支持 添加新单词 和 查找字符串是否与任何先前添加的字符串匹配 。</p>
<p>实现词典类 <code>WordDictionary</code> </p>
<ul>
<li><code>WordDictionary()</code> 初始化词典对象</li>
<li><code>void addWord(word)</code><code>word</code> 添加到数据结构中,之后可以对它进行匹配</li>
<li><code>bool search(word)</code> 如果数据结构中存在字符串与&nbsp;<code>word</code> 匹配,则返回 <code>true</code> ;否则,返回&nbsp; <code>false</code><code>word</code> 中可能包含一些 <code>'.'</code> ,每个&nbsp;<code>.</code> 都可以表示任何一个字母。</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例:</strong></p>
<pre>
<strong>输入:</strong>
["WordDictionary","addWord","addWord","addWord","search","search","search","search"]
[[],["bad"],["dad"],["mad"],["pad"],["bad"],[".ad"],["b.."]]
<strong>输出:</strong>
[null,null,null,null,false,true,true,true]
<strong>解释:</strong>
WordDictionary wordDictionary = new WordDictionary();
wordDictionary.addWord("bad");
wordDictionary.addWord("dad");
wordDictionary.addWord("mad");
wordDictionary.search("pad"); // 返回 False
wordDictionary.search("bad"); // 返回 True
wordDictionary.search(".ad"); // 返回 True
wordDictionary.search("b.."); // 返回 True
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= word.length &lt;= 25</code></li>
<li><code>addWord</code> 中的 <code>word</code> 由小写英文字母组成</li>
<li><code>search</code> 中的 <code>word</code> 由 '.' 或小写英文字母组成</li>
<li>最多调用 <code>10<sup>4</sup></code><code>addWord</code><code>search</code></li>
</ul>