当前位置:网站首页>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】
Catalog
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
674. The longest continuous increasing sequence
Given an unordered array of integers , Find the longest and Successive increasing subsequences , And return the length of the sequence .
Successive increasing subsequences It can be made up of two subscripts l and r(l < r) determine , If for each l <= i < r, There are nums[i] < nums[i + 1] , So the subsequence [nums[l], nums[l + 1], …, nums[r - 1], nums[r]] It's a continuous increasing subsequence .
### Knowledge points involved
Dynamic programming
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. Judge whether the matrix is a X matrix
If a square matrix satisfies the following All Conditions , It is called a X matrix :
All the elements on the diagonal of the matrix are No 0
All other elements in the matrix are 0
Give you a size of n x n A two-dimensional array of integers grid , Represents a square matrix . If grid It's a X matrix , return true ; otherwise , return false .

Knowledge points involved :
Two dimensional matrix for loop
Code section
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. The addition of integers in the form of arrays
The integer Array form num Is an array of numbers in left to right order .
for example , about num = 1321 , The array form is [1,3,2,1] .
Given num , The integer Array form , And integer k , return Integers num + k Of Array form .
Knowledge points involved
String conversion
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)))
边栏推荐
- mock. JS returns an array from the optional data in the object array
- How to buy bank financial products? Do you need a bank card?
- Openeuler prize catching activities, to participate in?
- 时间工具类
- 使用高斯Redis实现二级索引
- 微信公众号OAuth2.0授权登录并显示用户信息
- 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!!!
- Open source heavy ware! Chapter 9 the open source project of ylarn causal learning of Yunji datacanvas company will be released soon!
- Implement secondary index with Gaussian redis
- R语言ggplot2可视化:使用ggpubr包的ggqqplot函数可视化QQ图(Quantile-Quantile plot)
猜你喜欢

LeetCode_7_5

The project manager's "eight interview questions" is equal to a meeting

数据孤岛是企业数字化转型遇到的第一道险关

vulnhub之tre1

Implement secondary index with Gaussian redis

Redis——基本使用(key、String、List、Set 、Zset 、Hash、Geo、Bitmap、Hyperloglog、事务 )
让这个 CRMEB 单商户微信商城系统火起来,太好用了!

Nunjuks template engine

9 atomic operation class 18 Rohan enhancement

8 CAS
随机推荐
关于cv2.dnn.readNetFromONNX(path)就报ERROR during processing node with 3 inputs and 1 outputs的解决过程【独家发布】
mock.js从对象数组中任选数据返回一个数组
Time tools
力扣 1037.有效的回旋镖
小试牛刀之NunJucks模板引擎
mock. JS returns an array from the optional data in the object array
【剑指offer】剑指 Offer II 012. 左右两边子数组的和相等
Cuda版本不一致,编译apex报错
ASP.NET学习& asp‘s one word
841. 字符串哈希
R语言使用ggplot2函数可视化需要构建泊松回归模型的计数目标变量的直方图分布并分析构建泊松回归模型的可行性
Nunjuks template engine
YoloV6:YoloV6+Win10---训练自己得数据集
R语言ggplot2可视化:使用ggpubr包的ggqqplot函数可视化QQ图(Quantile-Quantile plot)
【STL】vector
MySQL、sqlserver oracle数据库连接方式
openEuler 有奖捉虫活动,来参与一下?
tp6 实现佣金排行榜
Automatic classification of defective photovoltaic module cells in electroluminescence images-论文阅读笔记
MIT科技评论文章:围绕Gato等模型的AGI炒作可能使人们忽视真正重要的问题