class Solution(object):
    def shortestDistance(self, wordsDict, word1, word2):
        index1 = -1
        index2 = -1
        minimum = float("inf")
        
        for i in range(len(wordsDict)):
            if word1 == wordsDict[i]:
                index1 = i
            if word2 == wordsDict[i]:
                index2 = i
            
            if index1 != -1 and index2 != -1:
                minimum = min(minimum, abs(index2 - index1))
        return minimum
        
23c1326a07ad95e705259affedb460470d28969e
<mask token>

class Solution(object):
    <mask token>

class Solution(object):

    def shortestDistance(self, wordsDict, word1, word2):
        index1 = -1
        index2 = -1
        minimum = float('inf')
        for i in range(len(wordsDict)):
            if word1 == wordsDict[i]:
                index1 = i
            if word2 == wordsDict[i]:
                index2 = i
            if index1 != -1 and index2 != -1:
                minimum = min(minimum, abs(index2 - index1))
        return minimum

class Solution(object):
    def shortestDistance(self, wordsDict, word1, word2):
        index1 = -1
        index2 = -1
        minimum = float("inf")
        
        for i in range(len(wordsDict)):
            if word1 == wordsDict[i]:
                index1 = i
            if word2 == wordsDict[i]:
                index2 = i
            
            if index1 != -1 and index2 != -1:
                minimum = min(minimum, abs(index2 - index1))
        return minimum
        