mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			14 lines
		
	
	
		
			682 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			14 lines
		
	
	
		
			682 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>You have a large text file containing words. Given any two 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>
 |