04 2024 档案

摘要:https://leetcode.cn/problems/top-k-frequent-elements/description/ 可以考虑使用HashMap+排序,不过直接使用优先队列也挺不错,可以使用大顶堆或小顶堆 class Solution { public int[] topKFreque 阅读全文
posted @ 2024-04-30 23:15 风乐 阅读(11) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/sliding-window-maximum/ 简单的滑动窗口,但是与ACM模式的维护数组不同,在leetcode定义单调队列类更加方便 class MyQueue{ // 单调队列实现,递减 Deque<Integer> deque = n 阅读全文
posted @ 2024-04-30 22:27 风乐 阅读(17) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/minimum-path-cost-in-a-grid 思路很简单,实现很恶心,主要由于我习惯于dp数组从1开始而不是0,这样在推导状态时由于grid是从0,0开始,而循环是从dp数组的1,1开始,因此在方程中一旦涉及到grid就需要把i,j 阅读全文
posted @ 2024-04-28 16:16 风乐 阅读(19) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/merge-intervals/?envType=study-plan-v2&envId=top-100-liked 合并区间练习题 typedef pair<int,int> PII; vector<PII> segs; class Sol 阅读全文
posted @ 2024-04-25 11:30 风乐 阅读(13) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/edit-distance/description/?envType=study-plan-v2&envId=top-100-liked 这是一个难题,关于序列DP的,官方的题解较为难懂,这里有一位前辈解释的很好 这里的状态定义是: dp[i 阅读全文
posted @ 2024-04-23 17:25 风乐 阅读(10) 评论(0) 推荐(0)
摘要:题面如下: https://www.acwing.com/problem/content/1252/ 这题需要从点出发,不需要管是红线还是蓝线,划线了就得合并两点到同一集合,只要当前线还未画之前,这两个端点是同一集合,那么画完后就是一个连通块,线组成的集合构成连通意味着成圈了,即得到答案 #incl 阅读全文
posted @ 2024-04-19 11:12 风乐 阅读(27) 评论(0) 推荐(0)
摘要:题面如下: https://www.acwing.com/problem/content/530/ 大致思路是:合并所有连接的空洞,判断下表面的空洞和上表面的空洞是否是同一集合集合 #include<iostream> #include<cstring> #include<cstdio> #incl 阅读全文
posted @ 2024-04-19 11:05 风乐 阅读(10) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/maximum-score-of-spliced-array/description/ 这一题应该算一个连续最大子数组思维题,要点是根据差数组去做,然后求最值 class Solution { public: int maximumsSpli 阅读全文
posted @ 2024-04-14 20:24 风乐 阅读(13) 评论(0) 推荐(0)