1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 19:18:14 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/算法题(国内版)/problem (Chinese)/单词距离 [find-closest-lcci].html

13 lines
665 B
HTML
Raw Normal View History

2022-03-27 20:38:29 +08:00
<p>有个内含单词的超大文本文件,给定任意两个单词,找出在这个文件中这两个单词的最短距离(相隔单词数)。如果寻找过程在这个文件中会重复多次,而每次寻找的单词不同,你能对此优化吗?</p>
<p><strong>示例:</strong></p>
<pre><strong>输入:</strong>words = [&quot;I&quot;,&quot;am&quot;,&quot;a&quot;,&quot;student&quot;,&quot;from&quot;,&quot;a&quot;,&quot;university&quot;,&quot;in&quot;,&quot;a&quot;,&quot;city&quot;], word1 = &quot;a&quot;, word2 = &quot;student&quot;
<strong>输出:</strong>1</pre>
<p>提示:</p>
<ul>
<li><code>words.length &lt;= 100000</code></li>
</ul>