245. Shortest Word Distance III
Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list.
word1 and word2 may be the same and they represent two individual words in the list.
Example:
Assume that words = ["practice", "makes", "perfect", "coding", "makes"]
.
Note: You may assume word1 and word2 are both in the list.
解题要点:
与第二题相似,不同的是要单独处理两个word一样的情况。
Last updated
Was this helpful?