当前位置:网站首页>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.
边栏推荐
- Voice assistant - Introduction and interaction process
- Numerical calculation method chapter5 Direct method for solving linear equations
- vscode 1.68变化与关注点(整理导入语句/实验性新命令中心等)
- ECMAScript6面试题
- 20220525 RCNN--->Faster RCNN
- Ecmascript6 interview questions
- AI fanaticism | come to this conference and work together on the new tools of AI!
- Web page performance optimization interview questions
- 石油储运生产 2D 可视化,组态应用赋能工业智慧发展
- 20220607. face recognition
猜你喜欢

Voice assistant - Multi round conversation (process implementation)

謀新局、促發展,桂林綠色數字經濟的頭雁效應

AI fanaticism | come to this conference and work together on the new tools of AI!
![[tutorial] deployment process of yolov5 based on tensorflow Lite](/img/d0/c38f27ad76b62b27cdeb68728e9c8c.jpg)
[tutorial] deployment process of yolov5 based on tensorflow Lite

Topic 1 Single_Cell_analysis(3)

Windows10 configuration database

Unity uses shaders to highlight the edges of ugu I pictures

Arrangement of statistical learning knowledge points -- maximum likelihood estimation (MLE) and maximum a posteriori probability (map)

Process terminated

Search and rescue strategy of underwater robot (FISH)
随机推荐
LeetCode笔记:Weekly Contest 295
Symfony 2: multiple and dynamic database connections
Unity uses shaders to highlight the edges of ugu I pictures
Connect to the database but cannot modify the data
Chapter 3 - Fundamentals of cryptography
2、 Eight, ten and hexadecimal conversion
Voice assistant - DM - distribution and sorting
Latex usage problems and skills summary (under update)
Meter Reading Instrument(MRI) Remote Terminal Unit electric gas water
Summary of machine learning + pattern recognition learning (VI) -- feature selection and feature extraction
@Datetimeformat @jsonformat differences
NaiveBayes function of R language e1071 package constructs naive Bayes model, predict function uses naive Bayes model to predict and reason test data, and table function constructs confusion matrix
Arrangement of statistical learning knowledge points -- maximum likelihood estimation (MLE) and maximum a posteriori probability (map)
Visual studio code batch comment and uncomment
数值计算方法 Chapter5. 解线性方程组的直接法
Topic 1 Single_ Cell_ analysis(3)
Leetcode34. find the first and last positions of elements in a sorted array
R语言使用RStudio将可视化结果保存为pdf文件(export--Save as PDF)
Support vector machine (SVM)
‘CMRESHandler‘ object has no attribute ‘_ timer‘,socket. gaierror: [Errno 8] nodename nor servname pro