上一页 1 2 3 4 5 6 7 ··· 20 下一页

2022年7月31日

LeetCode354 俄罗斯套娃信封问题

摘要: LeetCode354 俄罗斯套娃信封问题 排序后求最长上升子序列 注意对$y$值从大到小排序可以保证相同$x$只取一个$y$ class Solution: def maxEnvelopes(self, envelopes: List[List[int]]) -> int: envelopes.s 阅读全文

posted @ 2022-07-31 22:00 solvit 阅读(40) 评论(0) 推荐(0)

LeetCode689 三个无重叠子数组的最大和

摘要: LeetCode689 三个无重叠子数组的最大和 $dp[i][j]$表示前$j$个元素,选$i$个子区间的最优值 对于当前$j$,转移方程考虑是否以第$j$个元素为子区间的最后一个元素 $dp[i][j] = \max(dp[i][j - 1], dp[i - 1][j - k] + pre[j] 阅读全文

posted @ 2022-07-31 20:58 solvit 阅读(42) 评论(0) 推荐(0)

2022年7月29日

LeetCode152 乘积最大子数组

摘要: LeetCode152 乘积最大子数组 同时统计min和max即可考虑正负关系 class Solution(object): def maxProduct(self, nums): """ :type nums: List[int] :rtype: int """ f_min, f_max, l 阅读全文

posted @ 2022-07-29 10:15 solvit 阅读(22) 评论(0) 推荐(0)

2022年7月23日

LeetCode105 从前序与中序遍历序列构造二叉树

摘要: LeetCode105 从前序与中序遍历序列构造二叉树 模板题目. # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.va 阅读全文

posted @ 2022-07-23 19:52 solvit 阅读(29) 评论(0) 推荐(0)

2022年7月22日

LeetCode229 多数元素 II

摘要: LeetCode229 多数元素 II 通过消除元素的方法确定候选, 即候选元素可以被消除$\frac{n}{3}$次. class Solution: def majorityElement(self, nums: List[int]) -> List[int]: proposal_1, prop 阅读全文

posted @ 2022-07-22 11:29 solvit 阅读(34) 评论(0) 推荐(0)

LeetCode330 按要求补齐数组

摘要: LeetCode330 按要求补齐数组 贪心维护当前数字可覆盖区域, $r$表示$[1, r - 1]$区间被覆盖 对于当前$num[i]$, 如果$num[i] \le r$, 维护$r = r + num[i]$ 否则当前最优填入数字为$r$, 可以将区间扩展为$[1, 2\times r - 阅读全文

posted @ 2022-07-22 08:04 solvit 阅读(28) 评论(0) 推荐(0)

2022年7月21日

LeetCode495 提莫攻击

摘要: LeetCode495 提莫攻击 贪心维护最右 class Solution: def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int: time, n, r = 0, len(timeSeries), 阅读全文

posted @ 2022-07-21 17:16 solvit 阅读(15) 评论(0) 推荐(0)

2022年7月19日

LeetCode215 数组中的第K个最大元素(快排,python)

摘要: LeetCode215 数组中的第K个最大元素 快排写法 class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: k = len(nums) - k def qsort(l, r): if l == r: r 阅读全文

posted @ 2022-07-19 17:45 solvit 阅读(80) 评论(0) 推荐(0)

2022年7月12日

LeetCode875 爱吃香蕉的珂珂

摘要: LeetCode875 爱吃香蕉的珂珂 二分答案 class Solution: def minEatingSpeed(self, piles: List[int], h: int) -> int: l, r = 1, max(piles) def check(k): time = 0 for c 阅读全文

posted @ 2022-07-12 17:26 solvit 阅读(42) 评论(0) 推荐(0)

LeetCode面试题 16.16. 部分排序

摘要: LeetCode面试题 16.16. 部分排序 记录前缀max和后缀min,采用双指针拟合答案 class Solution: def subSort(self, array: List[int]) -> List[int]: n = len(array) if n == 0: return [-1 阅读全文

posted @ 2022-07-12 16:45 solvit 阅读(33) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 ··· 20 下一页

导航