当前位置:网站首页>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.
边栏推荐
- 20220525 RCNN--->Faster RCNN
- Compiling principle on computer -- functional drawing language (IV): semantic analyzer
- 2021.10.29-30 scientific research log
- Visual studio code batch comment and uncomment
- 20220524 deep learning technology points
- 最新hbuilderX编辑uni-app项目运行于夜神模拟器
- vscode 1.68变化与关注点(整理导入语句/实验性新命令中心等)
- 2021.10.27-28 scientific research log
- R语言将dataframe数据中指定数据列的数据从小数转化为百分比表示、数据转换为百分数
- Conda创建虚拟环境报错,问题解决
猜你喜欢

Voice assistant -- Qu -- semantic role annotation and its application

Topic 1 Single_Cell_analysis(2)

Symfony 2: multiple and dynamic database connections

Scoring prediction problem

Voice assistant - overall architecture and design

Seeking for a new situation and promoting development, the head goose effect of Guilin's green digital economy

Voice assistant - Measurement Indicators

Dynamic simulation method of security class using Matlab based Matpower toolbox

Voice assistant - Introduction and interaction process

Vs 2019 MFC connects and accesses access database class library encapsulation through ace engine
随机推荐
@Datetimeformat @jsonformat differences
Improvement of hash function based on life game (continued 2)
Topic 1 Single_ Cell_ analysis(3)
Process terminated
Chapter 8 - firewall, Chapter 9 - Intrusion Detection
Question bank and answers of special operation certificate examination for safety management personnel of hazardous chemical business units in 2022
qt. qpa. plugin: Could not load the Qt platform plugin “xcb“ in “***“
Seeking for a new situation and promoting development, the head goose effect of Guilin's green digital economy
Chapter 4 - key management and distribution
Visual studio code batch comment and uncomment
Voice assistant -- Qu -- semantic role annotation and its application
Leetcode34. find the first and last positions of elements in a sorted array
Summary of machine learning + pattern recognition learning (VI) -- feature selection and feature extraction
What is a good recommendation system?
Chapter 3 - Fundamentals of cryptography
[redistemplate method details]
Solve mapper duplication problem in reverse engineering
ECMAScript6面试题
20220525 RCNN--->Faster RCNN
Compiling principle on computer -- function drawing language (III): parser