class Solution:
def findRestaurant(self, list1: List[str], list2: List[str]) -> List[str]:
# 如果使用字典,先都统计出来,然后再排序,也是可行的,但是我的这种写法也是很有趣的。
sum_of_index = 0
ret = []
for i in list1:
if i in list2:
list1.index(i) + list2.index(i)
# d[i] = list1.index(i) + list2.index(i)
# ret.append(i)
if list1.index(i) + list2.index(i) == sum_of_index:
ret.append(i)
if list1.index(i) + list2.index(i) > sum_of_index:
if not ret:
ret.append(i)
sum_of_index = list1.index(i) + list2.index(i)
if list1.index(i) + list2.index(i) < sum_of_index:
if ret:
ret.clear()
ret.append(i)
# print(ret)
return ret
网友评论