当前位置:网站首页>Leetcode notes: Weekly contest 275
Leetcode notes: Weekly contest 275
2022-06-12 07:53:00 【Espresso Macchiato】
1. Topic 1
The link to question 1 is as follows :
1. Their thinking
There is nothing to say about this problem , Just check it according to the meaning of the topic .
2. Code implementation
give python The code implementation is as follows :
class Solution:
def checkValid(self, matrix: List[List[int]]) -> bool:
n = len(matrix)
if any(len(set(l)) != n for l in matrix):
return False
if any(len(set([matrix[j][i] for j in range(n)])) != n for i in range(n)):
return False
return True
The submitted code was evaluated : Time consuming 854ms, Take up memory 14.7MB.
2. Topic two
The link to question 2 is as follows :
1. Their thinking
This question is more or less a clever one , Because the final exchange result must be a series of 1 And the rest 0, that , We just need to investigate 1 Total of ( Remember as l), Then look at all the lengths l Among the continuous substrings of 0 The number of , The number is the number of times to exchange .
Then we go to a minimum value .
2. Code implementation
give python The code implementation is as follows :
class Solution:
def minSwaps(self, nums: List[int]) -> int:
n, s = len(nums), sum(nums)
nums = [0] + nums + nums[:s]
accum = list(accumulate(nums))
return min(s - (accum[i+s] - accum[i]) for i in range(n))
The submitted code was evaluated : Time consuming 1324ms, Take up memory 25.9MB.
3. Topic three
The link to question 3 is as follows :
1. Their thinking
I don't have any good ideas for the time being , Just use one 26 An array of dimensions to express each word , Each dimension represents the number of times its corresponding letter appears , And let's see target Is the word that appears after deleting a character for each word in startwords among .
2. Code implementation
give python The code implementation is as follows :
class Solution:
def wordCount(self, startWords: List[str], targetWords: List[str]) -> int:
starts = set()
for w in startWords:
s = [0 for _ in range(26)]
for ch in w:
s[ord(ch) - ord('a')] += 1
starts.add(tuple(s))
res = 0
for w in targetWords:
s = [0 for _ in range(26)]
for ch in w:
s[ord(ch) - ord('a')] += 1
for i in range(26):
if s[i] > 0:
s[i] -= 1
if tuple(s) in starts:
res += 1
break
s[i] += 1
return res
The submitted code was evaluated : Time consuming 2088ms, Take up memory 37.8MB.
4. Topic four
The link to question 4 is as follows :
1. Their thinking
This question feels a little watery , I used a greedy algorithm , Obviously all the watering time is necessary , What can be reduced is the growth time , So we arrange them in reverse chronological order , Then plant in turn , After that, just look at the shortest time required for each flower to grow .
2. Code implementation
give python The code implementation is as follows :
class Solution:
def earliestFullBloom(self, plantTime: List[int], growTime: List[int]) -> int:
times = sorted(zip(plantTime, growTime), key=lambda x: (x[1], -x[0]), reverse=True)
res = 0
used = 0
for pt, gt in times:
res = max(res, used + pt + gt)
used += pt
return res
The submitted code was evaluated : Time consuming 1959ms, Take up memory 41.5MB.
边栏推荐
- Rich dad, poor dad Abstract
- Leetcode notes: Weekly contest 296
- The R language converts the data of the specified data column in the dataframe data from decimal to percentage representation, and the data to percentage
- Leetcode notes: Weekly contest 295
- R语言使用neuralnet包构建神经网络回归模型(前馈神经网络回归模型),计算模型在测试集上的MSE值(均方误差)
- Process terminated
- Chapter 4 - key management and distribution
- Multithread decompression of tar
- [RedisTemplate方法详解]
- Parameter estimation of Weibull distribution
猜你喜欢

Topic 1 Single_Cell_analysis(3)

What is a good recommendation system?

Support vector machine (SVM)

Voice assistant -- Architecture and design of Instruction Assistant

Topic 1 Single_ Cell_ analysis(3)

Voice assistant - those classification models used in the assistant

Voice assistant - potential skills and uncalled call technique mining

Chapter 3 - Fundamentals of cryptography

Voice assistant - Qu - ner and intention slot model

Meter Reading Instrument(MRI) Remote Terminal Unit electric gas water
随机推荐
20220525 RCNN--->Faster RCNN
Process terminated
Voice assistant - Qu - single entity recall
Vscode 1.68 changes and concerns (sorting and importing statements / experimental new command center, etc.)
AJ project: online bank project summary
Compiling principle on computer -- functional drawing language (I)
2022 G3 boiler water treatment recurrent training question bank and answers
Meter Reading Instrument(MRI) Remote Terminal Unit electric gas water
vscode 1.68变化与关注点(整理导入语句/实验性新命令中心等)
Voice assistant -- Architecture and design of Instruction Assistant
L'effet de l'oie sauvage sur l'économie numérique verte de Guilin
Topic 1 Single_ Cell_ analysis(2)
数值计算方法 Chapter5. 解线性方程组的直接法
Topic 1 Single_ Cell_ analysis(3)
经典论文回顾:Palette-based Photo Recoloring
The project file contains toolsversion= "14.0". This toolset may be unknown or missing workarounds
The R language catools package divides the data, the scale function scales the data, the KNN function of the class package constructs a k-nearest neighbor classifier, and compares the model accuracy u
2、 Eight, ten and hexadecimal conversion
20220526 yolov1-v5
Arrangement of statistical learning knowledge points gradient descent, least square method, Newton method