当前位置:网站首页>[leetcode weekly replay] 302 weekly 20220717
[leetcode weekly replay] 302 weekly 20220717
2022-07-19 10:51:00 【Seven water Shuliang】
[LeetCode Weekly replay ] The first 302 Weekly match 20220717
One 、 Summary of this week's race
- It's all simulation questions ,wa A crazy ranking o(╥﹏╥)o.

Two 、 [Easy] 6120. How many pairs can an array form
link : 6120. How many pairs can an array form
1. Title Description

2. Thought analysis
grading Easy.
Count the number of occurrences of each number , The same number can be removed once every two ; How many odd numbers remain is the remaining number .
3. Code implementation
class Solution:
def numberOfPairs(self, nums: List[int]) -> List[int]:
cnt = Counter(nums)
ans1 = sum(v&1 for k,v in cnt.items())
ans0 = sum(v//2 for k,v in cnt.items())
return [ans0,ans1]
3、 ... and 、[Medium] 6164. The maximum sum of digits and equal pairs
link : 6164. The maximum sum of digits and equal pairs
1. Title Description

2. Thought analysis
grading Medium.
- Use a hash table to record each digit and the associated digit .
- Traverse this hash table , Update a group of numbers by adding the two largest numbers ans that will do .
3. Code implementation
class Solution:
def maximumSum(self, nums: List[int]) -> int:
g=defaultdict(list)
def sum_digit(a):
return sum(int(i) for i in str(a))
for a in nums:
g[sum_digit(a)].append(a)
ans = -1
for k,v in g.items():
if len(v)<2:
continue
v.sort()
ans = max(ans,v[-1]+v[-2])
return ans
Four 、[Medium] 6121. Query the number K Small numbers
link : 6121. Query the number K Small numbers
1. Title Description

2. Thought analysis
grading Medium.
It's a long question , But violent simulation is enough .
3. Code implementation
class Solution:
def smallestTrimmedNumbers(self, nums: List[str], queries: List[List[int]]) -> List[int]:
m,n = len(nums),len(nums[0])
ans = []
for k,t in queries:
arr = [(num[-t:],i) for i,num in enumerate(nums)]
arr.sort()
x = arr[k-1]
ans.append(x[1])
return ans
5、 ... and 、[Hard] 6122. The minimum number of deletions that make the array divisible
link : 6122. The minimum number of deletions that make the array divisible
1. Title Description

2. Thought analysis
- aliquot b All elements in are equal to divisible b The greatest common divisor in gcd.
- Preprocessing b Of gcd, Yes a After sorting, find the first one that can divide gcd The element position of .
3. Code implementation
class Solution:
def minOperations(self, nums: List[int], numsDivide: List[int]) -> int:
n = len(nums)
d = numsDivide[0]
for i in range(1,len(numsDivide)):
d = gcd(d,numsDivide[i])
nums.sort()
ans = 0
for i,v in enumerate(nums):
if d%v==0:
break
ans += 1
if ans == n:
return -1
else:
return ans
边栏推荐
- LeetCode 2249. Count the number of grid points in the circle
- Connected graph (union search set)
- [acwing] 60th weekly match b- 4495 Array operation
- Game theory (Depu) and investment (40/100)
- vSphere 下借助 vDS 或 NSX 做端口镜像的方法总结
- Prospect of 6G global convergence network
- MySQL query error
- SAP S4 Material Management 库存模块 MARD 数据库表读取技术细节介绍
- Structure the combat battalion | module 7
- Takeout ordering system based on wechat applet
猜你喜欢

Data Lake solutions of various manufacturers

电商销售数据分析与预测(日期数据统计、按天统计、按月统计)

常见集合特性

Win10 start key click no response

LeetCode 2325. Decrypt message (map)

antd 下拉多选传值到后台做查询操作

【在vivado中调ila IP核】

Beego framework realizes file upload + seven cattle cloud storage

如何在双链笔记软件中建立仪表盘和知识库?以嵌入式小组件库 NotionPet 为例

腾讯云服务器利用镜像部署WordPress个人网站!
随机推荐
常见集合特性
vulnhub inclusiveness: 1
IP SAN拥有独立的文件系统,应用服务器通过网络共享协议访问到IP SAN后,可以对文件系统中的文件进行读写操作
SAP ABAP CDS view 视图的 Replacement 技术介绍
【设计过程】.NET ORM FreeSql WhereDynamicFilter 动态表格查询功能
因果学习将开启下一代AI浪潮?九章云极DataCanvas正式发布YLearn因果学习开源项目
LeetCode 2315. 统计星号(字符串)
Thinking about the integrated communication of air, space and earth based on the "7.20 Zhengzhou rainstorm"
线程池原理
数据库面基知识汇总后
破案了卧槽---从MQ消费的逻辑怎么改代码都不生效
从“被动”到“主动”,ZETA技术助力“RFID2.0”升级该如何实现?
从预测到决策,九章云极DataCanvas推出YLearn因果学习开源项目
37. Flex layout
人大、微软等提出InclusiveFL:异构设备上的包容性联邦学习
Satellite network capacity improvement method based on network coding
Game theory (Depu) and investment (40/100)
6G中的卫星通信高效天基计算技术
How to build dashboard and knowledge base in double chain note taking software? Take the embedded widget library notionpet as an example
Leetcode丑数题解