当前位置:网站首页>力扣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
边栏推荐
- pom.xml 配置文件标签:dependencies 和 dependencyManagement 区别
- Sword finger offer II 013 Sum of two-dimensional submatrix
- vulnhub之tre1
- el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
- Kirin Xin'an with heterogeneous integration cloud financial information and innovation solutions appeared at the 15th Hunan Financial Technology Exchange Conference
- The DBSCAN function of FPC package of R language performs density clustering analysis on data, checks the clustering labels of all samples, and the table function calculates the two-dimensional contin
- 关于cv2.dnn.readNetFromONNX(path)就报ERROR during processing node with 3 inputs and 1 outputs的解决过程【独家发布】
- mock. JS returns an array from the optional data in the object array
- 力扣 2315.统计星号
- Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
猜你喜欢
转置卷积理论解释(输入输出大小分析)
Matplotlib drawing 3D graphics
项目经理『面试八问』,看了等于会了
Implement secondary index with Gaussian redis
The strength index of specialized and new software development enterprises was released, and Kirin Xin'an was honored on the list
Flink并行度和Slot详解
mysql 的一些重要知识
vulnhub之Funfox2
Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
Kirin Xin'an joins Ningxia commercial cipher Association
随机推荐
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
pom. Brief introduction of XML configuration file label function
How to buy bank financial products? Do you need a bank card?
力扣 459. 重复的子字符串
国家网信办公布《数据出境安全评估办法》:累计向境外提供10万人信息需申报
Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
网信办公布《数据出境安全评估办法》,9 月 1 日起施行
ASP.NET幼儿园连锁管理系统源码
vulnhub之Funfox2
The state cyberspace Office released the measures for data exit security assessment: 100000 information provided overseas needs to be declared
Sword finger offer II 013 Sum of two-dimensional submatrix
Open source heavy ware! Chapter 9 the open source project of ylarn causal learning of Yunji datacanvas company will be released soon!
一锅乱炖,npm、yarn cnpm常用命令合集
The project manager's "eight interview questions" is equal to a meeting
IP tools
openEuler 资源利用率提升之道 01:概论
831. KMP字符串
9 原子操作类之18罗汉增强
[RT thread env tool installation]
PMP對工作有益嗎?怎麼選擇靠譜平臺讓備考更省心省力!!!