当前位置:网站首页>Force buckle 599 Minimum index sum of two lists
Force buckle 599 Minimum index sum of two lists
2022-07-07 20:06:00 【Tomorrowave】
599. The minimum index sum of two lists
hypothesis Andy and Doris Want to choose a restaurant for dinner , And they all have a list of their favorite restaurants , The name of each restaurant is represented by a string .
You need to help them use the least index and find their favorite restaurants . If there is more than one answer , Then all the answers are output regardless of the order . You can assume that the answer always exists .
Knowledge points involved :
Dictionaries
Code section
class Solution:
def findRestaurant(self, list1: List[str], list2: List[str]) -> List[str]:
favorite_restaurant={
}
min_f=[]
for x in list1:
if x in list2:
favorite_restaurant[x]=list2.index(x)+list1.index(x)
minv=min(favorite_restaurant.values())
for i,j in favorite_restaurant.items():
if j==minv:
min_f.append(i)
return min_f
边栏推荐
猜你喜欢
剑指 Offer II 013. 二维子矩阵的和
CSDN语法说明
模拟实现string类
openEuler 资源利用率提升之道 01:概论
LeetCode力扣(剑指offer 36-39)36. 二叉搜索树与双向链表37. 序列化二叉树38. 字符串的排列39. 数组中出现次数超过一半的数字
数据孤岛是企业数字化转型遇到的第一道险关
Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
mysql 的一些重要知识
Automatic classification of defective photovoltaic module cells in electroluminescence images-论文阅读笔记
最多可以参加的会议数目[贪心 + 优先队列]
随机推荐
Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
8 CAS
多个线程之间如何协同
力扣 643. 子数组最大平均数 I
让这个 CRMEB 单商户微信商城系统火起来,太好用了!
力扣 2319. 判断矩阵是否是一个 X 矩阵
JVM GC垃圾回收简述
[RT thread env tool installation]
LC: string conversion integer (ATOI) + appearance sequence + longest common prefix
LeetCode_ 7_ five
How to buy bank financial products? Do you need a bank card?
ASP.NET体育馆综合会员管理系统源码,免费分享
My creation anniversary
equals 方法
项目经理『面试八问』,看了等于会了
银行理财产品怎么买?需要办银行卡吗?
R语言ggplot2可视化:使用ggpubr包的ggecdf函数可视化分组经验累积密度分布函数曲线、linetype参数指定不同分组曲线的线型
Training IX basic configuration of network services
一锅乱炖,npm、yarn cnpm常用命令合集
Redis——基本使用(key、String、List、Set 、Zset 、Hash、Geo、Bitmap、Hyperloglog、事务 )