随笔分类 -  Algorithm

一些算法题,主要语言是C++,可能会偶然有python
摘要:周赛链接:https://www.acwing.com/activity/content/competition/problem_list/2644/ AcWing 4722. 数列元素 #include <iostream> using namespace std; int n; int main 阅读全文
posted @ 2022-11-29 18:37 星星亮了欸 阅读(27) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.cn/problems/non-overlapping-intervals/description/ 线性dp TLE class Solution { public: int f[200010]; int a[200010]; int eraseOverlapIn 阅读全文
posted @ 2022-11-23 11:43 星星亮了欸 阅读(33) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.cn/problems/binary-tree-maximum-path-sum/description/ dp, 树上搜索 因为值有负数,所以针对一个节点的更新,有四种情况: 节点值本身 节点值 + 左子树 节点值 + 右子树 节点值 + 左子树 + 右子树 要注 阅读全文
posted @ 2022-11-22 21:13 星星亮了欸 阅读(32) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.cn/problems/top-k-frequent-elements/description/ 主要是用hash表 数据个数给定了,但是数据范围没有给定,可能是负数。 所以需要map来记录每个数的id class Solution { public: map<in 阅读全文
posted @ 2022-11-22 20:09 星星亮了欸 阅读(25) 评论(0) 推荐(0) 编辑
摘要:原题链接:https://leetcode.cn/problems/maximum-subarray/description/ WA了一次,是因为没有考虑到负数的情况 AC代码: class Solution { public: int maxSubArray(vector<int>& nums) 阅读全文
posted @ 2022-11-21 22:45 星星亮了欸 阅读(25) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.cn/problems/lexicographical-numbers/description/ 想像成一颗树的遍历 AC代码: class Solution { public: vector<int> lexicalOrder(int n) { int cur = 阅读全文
posted @ 2022-11-21 22:45 星星亮了欸 阅读(25) 评论(0) 推荐(0) 编辑
摘要:[199] 二叉树的右视图 题目链接: https://leetcode.cn/problems/binary-tree-right-side-view/description/ WA 一开始的想法是遍历二叉树,只需要右分枝即可。但是如果右边没有节点,就可以看到左边的点。 class Solutio 阅读全文
posted @ 2022-11-21 22:45 星星亮了欸 阅读(28) 评论(0) 推荐(0) 编辑
摘要:原题链接:https://leetcode.cn/problems/maximum-subarray/description/ 慎用自增/自减符号,不要偷懒,写两行代码更为保险 以下两段代码的效果是不一样的 num[p - 1] *= num[p--]; num[p - 1] *= num[p]; 阅读全文
posted @ 2022-11-21 22:45 星星亮了欸 阅读(29) 评论(0) 推荐(0) 编辑
摘要:https://www.acwing.com/problem/content/4607/ #哈希表 题意: 初始时空集{}, 进行 t 次操作,操作分为: + x,将一个非负整数 x 添加至集合中。注意,集合中可以存在多个相同的整数。 - x,从集合中删除一个非负整数 x。可以保证执行此操作时,集合 阅读全文
posted @ 2022-09-07 12:45 星星亮了欸 阅读(38) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示