当前位置:网站首页>力扣 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)))
边栏推荐
- 841. 字符串哈希
- R language ggplot2 visualization: use the ggqqplot function of ggpubr package to visualize the QQ graph (Quantitative quantitative plot)
- 9 atomic operation class 18 Rohan enhancement
- 【Confluence】JVM内存调整
- PMP对工作有益吗?怎么选择靠谱平台让备考更省心省力!!!
- R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
- Compiler optimization (4): inductive variables
- PMP practice once a day | don't get lost in the exam -7.7
- 力扣 643. 子数组最大平均数 I
- LC:字符串转换整数 (atoi) + 外观数列 + 最长公共前缀
猜你喜欢

PMP对工作有益吗?怎么选择靠谱平台让备考更省心省力!!!

位运算介绍
![最多可以参加的会议数目[贪心 + 优先队列]](/img/f3/e8e939e0393efc404cc159d7d33364.png)
最多可以参加的会议数目[贪心 + 优先队列]

Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!

LeetCode力扣(剑指offer 36-39)36. 二叉搜索树与双向链表37. 序列化二叉树38. 字符串的排列39. 数组中出现次数超过一半的数字

Simulate the implementation of string class

ASP. Net kindergarten chain management system source code

Openeuler prize catching activities, to participate in?

Sword finger offer II 013 Sum of two-dimensional submatrix

小试牛刀之NunJucks模板引擎
随机推荐
gorilla官方:golang开websocket client的示例代码
Redis——基本使用(key、String、List、Set 、Zset 、Hash、Geo、Bitmap、Hyperloglog、事务 )
LeetCode力扣(剑指offer 36-39)36. 二叉搜索树与双向链表37. 序列化二叉树38. 字符串的排列39. 数组中出现次数超过一半的数字
Semantic SLAM源码解析
IP tools
位运算介绍
PMP對工作有益嗎?怎麼選擇靠譜平臺讓備考更省心省力!!!
R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
YoloV6:YoloV6+Win10---训练自己得数据集
LeetCode_7_5
Automatic classification of defective photovoltaic module cells in electroluminescence images-论文阅读笔记
Boot 和 Cloud 的版本选型
R language ggplot2 visualization: use the ggviolin function of ggpubr package to visualize the violin diagram, set the palette parameter to customize the filling color of violin diagrams at different
开源重器!九章云极DataCanvas公司YLearn因果学习开源项目即将发布!
Chapter 9 Yunji datacanvas was rated as 36 krypton "the hard core technology enterprise most concerned by investors"
mock. JS returns an array from the optional data in the object array
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!!!
PMP practice once a day | don't get lost in the exam -7.7
让这个 CRMEB 单商户微信商城系统火起来,太好用了!
A pot of stew, a collection of common commands of NPM and yarn cnpm