当前位置:网站首页>力扣599. 两个列表的最小索引总和
力扣599. 两个列表的最小索引总和
2022-07-07 17:53:00 【Tomorrowave】
599. 两个列表的最小索引总和
假设 Andy 和 Doris 想在晚餐时选择一家餐厅,并且他们都有一个表示最喜爱餐厅的列表,每个餐厅的名字用字符串表示。
你需要帮助他们用最少的索引和找出他们共同喜爱的餐厅。 如果答案不止一个,则输出所有答案并且不考虑顺序。 你可以假设答案总是存在。
涉及知识点:
字典
代码部分
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
边栏推荐
- LeetCode_7_5
- LC: string conversion integer (ATOI) + appearance sequence + longest common prefix
- Time tools
- 银行理财产品怎么买?需要办银行卡吗?
- torch.nn.functional.pad(input, pad, mode=‘constant‘, value=None)记录
- 华南X99平台打鸡血教程
- Flink并行度和Slot详解
- R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
- 841. 字符串哈希
- Redis——基本使用(key、String、List、Set 、Zset 、Hash、Geo、Bitmap、Hyperloglog、事务 )
猜你喜欢
Implement secondary index with Gaussian redis
8 CAS
Empowering smart power construction | Kirin Xin'an high availability cluster management system to ensure the continuity of users' key businesses
Compiler optimization (4): inductive variables
转置卷积理论解释(输入输出大小分析)
[RT thread env tool installation]
LeetCode_7_5
9 原子操作类之18罗汉增强
论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》
mock. JS returns an array from the optional data in the object array
随机推荐
Visual Studio 插件之CodeMaid自动整理代码
银行理财产品怎么买?需要办银行卡吗?
Make this crmeb single merchant wechat mall system popular, so easy to use!
Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
Le PGR est - il utile au travail? Comment choisir une plate - forme fiable pour économiser le cœur et la main - d'œuvre lors de la préparation de l'examen!!!
编译器优化那些事儿(4):归纳变量
R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the dot strip plot, set the position parameter, and configure the separation degree of different grouped
Semantic SLAM源码解析
MSE API学习
2022年投资哪个理财产品收益高?
My creation anniversary
模拟实现string类
转置卷积理论解释(输入输出大小分析)
RESTAPI 版本控制策略【eolink 翻译】
Redis——基本使用(key、String、List、Set 、Zset 、Hash、Geo、Bitmap、Hyperloglog、事务 )
How to cooperate among multiple threads
PMP每日一练 | 考试不迷路-7.7
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
openEuler 有奖捉虫活动,来参与一下?
8 CAS