谨慎飞鸟

文章
8
资源
0
加入时间
3年1月8天

单词的距离(leetcode)

有个内含单词的超大文本文件,给定任意两个单词,找出在这个文件中这两个单词的最短距离(相隔单词数),如果寻找过程在这个文件中重复多次,而每次寻找的单词不同,你能优化吗?方法一 ,双指法class Solution: def findClosest(self, words, word1, word2): dis = float("inf") # 正无穷大 w1,w2 = -1,-1 i = 0 while i &