当前位置:网站首页>力扣 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
674. 最长连续递增序列
给定一个未经排序的整数数组,找到最长且 连续递增的子序列,并返回该序列的长度。
连续递增的子序列 可以由两个下标 l 和 r(l < r)确定,如果对于每个 l <= i < r,都有 nums[i] < nums[i + 1] ,那么子序列 [nums[l], nums[l + 1], …, nums[r - 1], nums[r]] 就是连续递增子序列。
###涉及知识点
动态规划
class Solution:
def findLengthOfLCIS(self, nums: List[int]) -> int:
ans=[1 for _ in range(len(nums))]
for i in range(1,len(nums)):
if nums[i]>nums[i-1]:
ans[i]=ans[i-1]+1
return max(ans)
2319. 判断矩阵是否是一个 X 矩阵
如果一个正方形矩阵满足下述 全部 条件,则称之为一个 X 矩阵 :
矩阵对角线上的所有元素都 不是 0
矩阵中所有其他元素都是 0
给你一个大小为 n x n 的二维整数数组 grid ,表示一个正方形矩阵。如果 grid 是一个 X 矩阵 ,返回 true ;否则,返回 false 。

涉及知识点:
二维矩阵的for循环
代码部分
class Solution:
def checkXMatrix(self, grid: List[List[int]]) -> bool:
for i in range(len(grid[0])):
for j in range(len(grid)):
if i==j or len(grid)-j-1==i :
if grid[i][j]==0:
return False
else:
if (grid[i][j]!=0):
return False
return True
989. 数组形式的整数加法
整数的 数组形式 num 是按照从左到右的顺序表示其数字的数组。
例如,对于 num = 1321 ,数组形式是 [1,3,2,1] 。
给定 num ,整数的 数组形式 ,和整数 k ,返回 整数 num + k 的 数组形式 。
涉及知识点
字符串的转换
class Solution:
def addToArrayForm(self, num: List[int], k: int) -> List[int]:
return [int(i) for i in str((int(str(num)[1:-1:3]))+k)]
class Solution:
def addToArrayForm(self, A: List[int], K: int) -> List[int]:
return list(map(int,str(int(''.join(map(str,A))) + K)))
边栏推荐
- 模拟实现string类
- pom.xml 配置文件标签作用简述
- 831. KMP字符串
- Make insurance more "safe"! Kirin Xin'an one cloud multi-core cloud desktop won the bid of China Life Insurance, helping the innovation and development of financial and insurance information technolog
- [confluence] JVM memory adjustment
- 让这个 CRMEB 单商户微信商城系统火起来,太好用了!
- 毕业季|遗憾而又幸运的毕业季
- 凌云出海记 | 赛盒&华为云:共助跨境电商行业可持续发展
- R language ggplot2 visualization: use the ggecdf function of ggpubr package to visualize the grouping experience cumulative density distribution function curve, and the linetype parameter to specify t
- Version selection of boot and cloud
猜你喜欢

vulnhub之school 1

Classification automatique des cellules de modules photovoltaïques par défaut dans les images de lecture électronique - notes de lecture de thèse

J ü rgen schmidhub reviews the 25th anniversary of LSTM papers: long short term memory All computable metaverses. Hierarchical reinforcement learning (RL). Meta-RL. Abstractions in generative adversar

Automatic classification of defective photovoltaic module cells in electroluminescence images-论文阅读笔记

The strength index of specialized and new software development enterprises was released, and Kirin Xin'an was honored on the list

openEuler 资源利用率提升之道 01:概论

Ways to improve the utilization of openeuler resources 01: Introduction

Interpretation of transpose convolution theory (input-output size analysis)

华南X99平台打鸡血教程

小试牛刀之NunJucks模板引擎
随机推荐
【RT-Thread env 工具安装】
力扣 1232.缀点成线
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置palette参数自定义不同水平小提琴图的填充色、add参数在小提琴图添加箱图
mock.js从对象数组中任选数据返回一个数组
R语言dplyr包select函数、group_by函数、filter函数和do函数获取dataframe中指定因子变量中指定水平中特定数值数据列的值第三大的值
MySQL、sqlserver oracle数据库连接方式
equals 方法
Version selection of boot and cloud
Sword finger offer II 013 Sum of two-dimensional submatrix
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
R language uses ggplot2 function to visualize the histogram distribution of counting target variables that need to build Poisson regression model, and analyzes the feasibility of building Poisson regr
一锅乱炖,npm、yarn cnpm常用命令合集
转置卷积理论解释(输入输出大小分析)
关于自身的一些安排
mock. JS returns an array from the optional data in the object array
位运算介绍
Make insurance more "safe"! Kirin Xin'an one cloud multi-core cloud desktop won the bid of China Life Insurance, helping the innovation and development of financial and insurance information technolog
Tp6 realize Commission ranking
pom.xml 配置文件标签:dependencies 和 dependencyManagement 区别
sql 常用优化