Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list.
For example,
Assume that words = ["practice", "makes", "perfect", "coding", "makes"].
Given word1 = “coding”, word2 = “practice”, return 3.
Given word1 = "makes", word2 = "coding", return 1.
题意:给定一个数组和两个单词word1,word2,返回两者最近的距离
word1不等于word2,但是两者可能在数组中出现多次
分类:数组
解法1:遍历数组,当遍历到word1,word2,记录下位置,并且每次都计算最新的最小值
原文链接http://blog.youkuaiyun.com/crazy__chen/article/details/47859737