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.
assume word1 and word2 are both in the list, what I gonna do is go through the list and record the word1 and word2's location
时间复杂度 o(n)
Last updated