当前位置:网站首页>Leetcode notes: biweekly contest 83
Leetcode notes: biweekly contest 83
2022-07-26 19:10:00 【Espresso Macchiato】
- Match Links :https://leetcode.com/contest/biweekly-contest-83
0. Summary
This week's two games are also a little injured , All the big guys just need 7、8 Problems that can be solved in minutes , I just didn't think of a good idea for the two fourth questions , In the end, it was only after reading the answers of other big guys , Then I found that these two questions only need a few lines , It hurts ……
I feel that my recent state is really not very good , alas ……
1. Topic 1
The link to question 1 is as follows :
1. Their thinking
This question is rule based Translate what is given in the question 4 One situation is enough .
2. Code implementation
give python The code implementation is as follows :
class Solution:
def bestHand(self, ranks: List[int], suits: List[str]) -> str:
if len(set(suits)) == 1:
return "Flush"
cnt = Counter(ranks).values()
if max(cnt) >= 3:
return "Three of a Kind"
elif max(cnt) == 2:
return "Pair"
else:
return "High Card"
The submitted code was evaluated : Time consuming 34ms, Take up memory 13.9MB.
2. Topic two
The link to question 2 is as follows :
1. Their thinking
This problem is actually to find all the continuous in the original sequence 0 The subsequence , Then calculate the number of subsequences they can form , Finally, add all these numbers .
2. Code implementation
give python The code implementation is as follows :
class Solution:
def zeroFilledSubarray(self, nums: List[int]) -> int:
res, cnt = 0, 0
for x in nums:
if x == 0:
cnt += 1
else:
res += cnt * (cnt+1) // 2
cnt = 0
res += cnt * (cnt+1) // 2
return res
The submitted code was evaluated : Time consuming 1895ms, Take up memory 24.7MB.
3. Topic three
The link to question 3 is as follows :
1. Their thinking
The main difficulty of this problem is that we need to quickly find the smallest of each number index, Therefore, we need to establish an ordered index Array of , Then maintain this array all the time .
2. Code implementation
give python The code implementation is as follows :
class NumberContainers:
def __init__(self):
self.nums = []
self.index = defaultdict(list)
def change(self, index: int, number: int) -> None:
idx = bisect.bisect_left(self.nums, (index, -1))
if idx >= len(self.nums) or self.nums[idx][0] != index:
bisect.insort(self.nums, (index, number))
bisect.insort(self.index[number], index)
else:
x = self.nums[idx][1]
self.nums[idx] = (index, number)
bisect.insort(self.index[number], index)
self.index[x].pop(bisect.bisect_left(self.index[x], index))
return
def find(self, number: int) -> int:
return -1 if self.index[number] == [] else self.index[number][0]
The submitted code was evaluated : Time consuming 2350ms, Take up memory 58.5MB.
4. Topic four
The link to question 4 is as follows :
1. Their thinking
In fact, I didn't expect this question at the beginning , But after reading the answer, I found that it was actually quite simple , In fact, it is a simple construction problem .
We give a construction method , After the first round of all the numbers , So for a length of 1 The subsequence , We can always construct this sequence .
Suppose we can now complete a length of n n n Sequence , If we can have another round after it 1 → k 1 \to k 1→k The number of , Then we can construct any length of n + 1 n+1 n+1 The subsequence .
conversely , If there is a number that does not exist , Then we can always find a subsequence , So that this sequence cannot be successfully constructed .
2. Code implementation
give python The code implementation is as follows :
class Solution:
def shortestSequence(self, rolls: List[int], k: int) -> int:
seen = set()
res = 1
for x in rolls:
seen.add(x)
if len(seen) == k:
res += 1
seen = set()
return res
The submitted code was evaluated : Time consuming 1503ms, Take up memory 28.3MB.
边栏推荐
- 模型定义#pytorch学习
- Kubectl common commands and simple explanations
- MySQL - 函数及约束命令
- Multi thread learning notes -1.cas
- 中信建投启牛会员优惠开户安全吗,不知道是不是最低的佣金
- 2022G1工业锅炉司炉上岗证题库及模拟考试
- MES系统最全介绍来了
- Write a starter
- [yuntu said] issue 246 digital asset chain - your God of digital asset property protection!
- 2022年流动式起重机司机考试试题模拟考试平台操作
猜你喜欢

PMP每日一练 | 考试不迷路-7.26(包含敏捷+多选)

How many pairs can an array of leetcode simple questions form

FTP protocol

JS刷题计划——链表

【MySQL从入门到精通】【高级篇】(八)聚簇索引&非聚簇索引&联合索引

SMMU carding

Operations research 69 | explanation of classic examples of dynamic planning

Comparison of advantages and disadvantages between SD NAND and EMMC

MapReduce(二)

The United States, Japan and South Korea jointly developed 6G with the intention of anti surpassing, but China has long been prepared
随机推荐
Use notes of Lichuang EDA
In this competition, you who can understand the topic have great potential
SSM integration configuration
Likeshop takeout order system is open source, 100% open source, no encryption
深度学习的数学基础
Distributed transaction Seata
微软默默给 curl 捐赠一万美元,半年后才通知
The diagram of user login verification process is well written!
【考研词汇训练营】Day 14 —— panini,predict,access,apologize,sense,transport,aggregation
2022 Shanghai safety officer C certificate operation certificate examination question bank simulated examination platform operation
一文详解MES系统给企业带来的5大好处,附应用场景
Racher deploys kubernetes cluster
.Net CLR GC 动态加载短暂堆阈值的计算及阈值超量的计算
The United States, Japan and South Korea jointly developed 6G with the intention of anti surpassing, but China has long been prepared
Brand new! Uncover the promotion route of Ali P5 Engineer ~p8 architect
2022年化工自动化控制仪表考题模拟考试平台操作
Flex layout
TypeScript阶段学习
The principle of database index, why use b+ tree, why not binary tree?
2022 tea master (intermediate) examination question simulation examination question bank and answers