代码拉取完成,页面将自动刷新
# Time: O((m + n) * l), m is the size of list1, n is the size of list2
# Space: O(m * l), l is the average length of string
class Solution(object):
def findRestaurant(self, list1, list2):
"""
:type list1: List[str]
:type list2: List[str]
:rtype: List[str]
"""
lookup = {}
for i, s in enumerate(list1):
lookup[s] = i
result = []
min_sum = float("inf")
for j, s in enumerate(list2):
if j > min_sum:
break
if s in lookup:
if j + lookup[s] < min_sum:
result = [s]
min_sum = j + lookup[s]
elif j + lookup[s] == min_sum:
result.append(s)
return result
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。