I'm working on a leetcode problem, and the problem is:
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.
The code I have so far:
class Solution(object):
def shortestDistance(self, words, word1, word2):
count = 0
count2 = 0
for i in word1:
count+=1
for j in word2:
count2 += 1
if count > count2:
return (count-count2)
else:
return (count2-count1)
s = Solution()
print(s.shortestDistance(["practice", "makes", "perfect", "coding", "makes"], "coding", "practice")
I've tried messing around with the tabbing and I still can't find a right way to align the code.
*the method is indented but for some reason would not indent here just fyi