随笔分类 - leetcode
摘要:Problem A 每个字符最多出现两次的最长子字符串 思路 双指针,使用一个数组记录每个字符的出现次数,当出现次数大于2时l往左收缩 其余情况往右划 代码 class Solution { public int maximumLengthSubstring(String s) { int n =
阅读全文
摘要:Problem A Apple Redistribution into Boxes 思路 求和-算所有苹果的和 然后将箱子从大到小排序 贪心即可 代码 class Solution { public int minimumBoxes(int[] apple, int[] capacity) { in
阅读全文
摘要:Problem A Distribute Elements Into Two Arrays I 思路 按照题意模拟即可. 代码 class Solution { public int[] resultArray(int[] nums) { int n = nums.length; int[] ans
阅读全文
摘要:Biweekly Contest 91 Problem A Number of Distinct Averages 思路 按照题意模拟即可,最后set的大小就是所求结果 代码 class Solution: def distinctAverages(self, nums: List[int]) ->
阅读全文
摘要:Weekly Contest 318 Problem A Apply Operations to an Array 思路 按照题意模拟即可 代码 class Solution: def applyOperations(self, nums: List[int]) -> List[int]: l =
阅读全文
摘要:Weekly Contest 317 Problem A Average Value of Even Numbers That Are Divisible by Three 思路 事实上就是求整除6的数的均值 代码 class Solution: def averageValue(self, num
阅读全文
摘要:Weekly Contest 316 Problem A Determine if Two Events Have Conflict 思路 先将时间转化为分钟单位,然后根据大小判断有没有交集即可 代码 class Solution: def haveConflict(self, event1: Li
阅读全文
摘要:Weekly Contest 315 Problem A Largest Positive Integer That Exists With Its Negative 思路 按照题目要求暴力求一下 代码 class Solution: def findMaxK(self, nums: List[in
阅读全文
摘要:Weekly Contest 314 Problem A The Employee That Worked on the Longest Task 思路 按照题目要求遍历一下就行 代码 class Solution: def hardestWorker(self, n: int, logs: Lis
阅读全文
摘要:Weekly Contest 313 Problem A Number of Common Factors 思路 数据范围小,直接暴力就完事了 代码 class Solution: def commonFactors(self, a: int, b: int) -> int: t = [] for
阅读全文
摘要:Weekly Contest 312 Problem A Sort the People 思路 水题,按值排序就行 代码 class Solution: def sortPeople(self, names: List[str], heights: List[int]) -> List[str]:
阅读全文
摘要:Weekly Contest 311 Problem A Smallest Even Multiple 思路 水题,判一下奇偶就行 代码 class Solution: def smallestEvenMultiple(self, n: int) -> int: if n%2==0: return
阅读全文
摘要:Weekly Contest 310 Problem A Most Frequent Even Element 思路 水题,用map存一下每个偶数数量然后统计就行 代码 class Solution: def mostFrequentEven(self, nums: List[int]) -> in
阅读全文
摘要:Weekly Contest 309 Problem A Check Distances Between Same Letters 思路 水题,遍历数组然后check一下就行 代码 class Solution: def checkDistances(self, s: str, distance:
阅读全文

浙公网安备 33010602011771号