mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
13 lines
715 B
HTML
13 lines
715 B
HTML
<p>You have a large text file containing words. Given any two different words, find the shortest distance (in terms of number of words) between them in the file. If the operation will be repeated many times for the same file (but different pairs of words), can you optimize your solution?</p>
|
|
|
|
|
|
|
|
<p><strong>Example: </strong></p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input: </strong>words = ["I","am","a","student","from","a","university","in","a","city"], word1 = "a", word2 = "student"
|
|
|
|
<strong>Output: </strong>1</pre>
|
|
|
|
|
|
|
|
<p>Note:</p>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li><code>words.length <= 100000</code></li>
|
|
|
|
</ul> |