随笔分类 -  LeetCode

摘要:AcWing 二分 + DFS树遍历 注意,虽然树中边的数量为顶点数-1,但是由于实际中将无向边存为两条有向边,所以数组开辟的边数个数要是顶点数的两倍。 #include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int 阅读全文
posted @ 2022-08-06 09:16 superPG 阅读(33) 评论(0) 推荐(0)
摘要:LeetCode 思维题 最小表示法 最小表示法题解 最小表示法: 最小表示法原理及实现在这篇blog中 AcWing 16进制读写 #include<bits/stdc++.h> using namespace std; int ans; int main() { while(scanf("%X" 阅读全文
posted @ 2022-08-03 15:35 superPG 阅读(22) 评论(0) 推荐(0)
摘要:LeetCode 模拟循环队列 https://leetcode.cn/problems/design-circular-queue/solution/672-by-sen-xm-n0on/ AcWing 想用getline实现一下,但是截取单词子串的时候取成 i = j 和 j = i 了,这样的 阅读全文
posted @ 2022-08-02 09:26 superPG 阅读(36) 评论(0) 推荐(0)
摘要:LeetCode BFS 层序遍历模板题 https://leetcode.cn/problems/maximum-level-sum-of-a-binary-tree/solution/1161-by-sen-xm-3q4t/ AcWing 周赛第二题 单点修改 + 区间修改 + 区间查询 如果暴 阅读全文
posted @ 2022-07-31 14:59 superPG 阅读(48) 评论(0) 推荐(0)
摘要:LeetCode 建图 + 并查集 + (筛法求质数) 如果暴力的建图,跑dfs最大连通图,建图会成为瓶颈,O(n^2)。 但是考虑到,A、B两数,A、B分别与其非1非自身的因数相连,如果A、B之间联通,那么A、B相互联通的那个点为公因数。可以将时间复杂度从依赖数据量的大小转移到依赖数据按数据范围。 阅读全文
posted @ 2022-07-30 09:38 superPG 阅读(69) 评论(0) 推荐(0)
摘要:LeetCode 模拟 特判 https://leetcode.cn/problems/valid-square/solution/593-mo-ni-by-sen-xm-73z6/ AcWing 思维题 对于A来说,其他蚂蚁碰头与否没有任何关系,即不与A碰头的蚂蚁可以看做相互之间直接穿过而不产生影 阅读全文
posted @ 2022-07-29 10:04 superPG 阅读(26) 评论(0) 推荐(0)
摘要:LeetCode STL 模拟 https://leetcode.cn/problems/rank-transform-of-an-array/solution/1331-stl-by-sen-xm-w57d/ AcWing 贪心 如果有解,从大到小依次判断是否能加入部分和中使得部分和不会超过目标和 阅读全文
posted @ 2022-07-28 10:06 superPG 阅读(33) 评论(0) 推荐(0)
摘要:LeetCode 模拟 + 字符串 题解如下: https://leetcode.cn/problems/fraction-addition-and-subtraction/solution/by-sen-xm-u2ak/ string转int: https://blog.csdn.net/xion 阅读全文
posted @ 2022-07-27 10:00 superPG 阅读(38) 评论(0) 推荐(0)
摘要:LeetCode 实现跳表 主要参考了以下几篇Bolg: https://www.acwing.com/blog/content/15081/ https://www.jianshu.com/p/9d8296562806 https://www.acwing.com/blog/content/486 阅读全文
posted @ 2022-07-26 10:19 superPG 阅读(32) 评论(0) 推荐(0)
摘要:LeetCode 题解如下: https://leetcode.cn/problems/complete-binary-tree-inserter/solution/919-by-sen-xm-2gev/ AcWing 模拟 #include <bits/stdc++.h> using namesp 阅读全文
posted @ 2022-07-25 09:28 superPG 阅读(35) 评论(0) 推荐(0)
摘要:LeetCode有意思,AcWing每日一题太简单了。 以后打算刷LeetCode每日一题+L站和A站的周赛了。 四道题的题解如下:(按赛题顺序排列) https://leetcode.cn/problems/first-letter-to-appear-twice/solution/6124-by 阅读全文
posted @ 2022-07-24 16:46 superPG 阅读(51) 评论(0) 推荐(0)