好久没打周赛了,打了一次周赛,简单的写个题解
2224. Minimum Number of Operations to Convert Time
题面:
1 | You are given two strings current and correct representing two 24-hour times. |
示例:
1 |
|
这题没啥好说的吧,直接暴力计算时间写就行
1 | class Solution: |
2225. Find Players With Zero or One Losses
题面:
1 | You are given an integer array matches where matches[i] = [winneri, loseri] indicates that the player winneri defeated player loseri in a match. |
示例:
1 | Example 1: |
这题实际上就遍历统计就行,时间复杂度 O(N) 空间复杂度 O(N)
1 | from collections import defaultdict |
2226. Maximum Candies Allocated to K Children
草,这题题号真有意思,尊。。。。
题面:
1 |
|
示例:
1 | Example 1: |
这题实际上最开始没想清楚,后面仔细想了下,实际上是个二分的题目
首先假设,我们所有的糖的和为 y, 假设被 k 整除后的值是 z(含义是最大的能够整数分割的数),那么我们题目里孩子能获得的最大的糖果的数量的值域一定是 [0,z]
这个区间是具备单调性(单调递增),那么就具备了二分的条件。那么我们二分的题目是什么?假设中间值是 mid ,我们计算每推糖果能够按照 mid 分成几份并求和,如果和小于 k ,那么意味着值比我们目标值大,否则则比目标值小。持续逼近即可
1 | from typing import List |
2227. Encrypt and Decrypt Strings
这题实际上比第三题简单
题面:
1 | You are given a character array keys containing unique characters and a string array values containing strings of length 2. You are also given another string array dictionary that contains all permitted original strings after decryption. You should implement a data structure that can encrypt or decrypt a 0-indexed string. |
示例:
1 | Input |
这题加密部分其实直接按照规则写就行了,然后解密部分有个方法就是提前将字典里面的值预计算一次,然后就能 O(1) 计算了
1 | from collections import Counter |