QuestionGiven an array of stringswordsDictand two different strings that already exist in the arrayword1andword2, returnthe shortest distance between these two words in the list.Example 1:Input: wordsDict = ["practice", "makes", "perfect", "coding", "makes"], word1 = "coding", word2 = "practice"
Output: 3Example 2:Input: wordsDict = ["practice", "makes", "perfect", "coding", "makes"], word1 = "makes", word2 = "coding"
Output: 1Constraints:2 <= wordsDict.length <= 3 * 1041 <= wordsDict[i].length <= 10wordsDict[i]consists of lowercase English letters.word1andword2are inwordsDict.word1 != word2Al
...
继续阅读
(12)