会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
博客园
首页
新随笔
联系
订阅
管理
上一页
1
···
14
15
16
17
18
19
20
21
22
···
33
下一页
2024年10月7日
根据数据量猜解法
摘要: 根据数据量猜解法 常数指令操作量 10^7 ~ 10^8,以此来猜测自己设计的算法有没有可能在规定时间内通过 消灭怪物 全排列 #include <vector> #include <iostream> using namespace std; int res; vector<pair<int, i
阅读全文
posted @ 2024-10-07 11:08 _Sylvan
阅读(21)
评论(0)
推荐(0)
2024年10月6日
N皇后问题
摘要: N皇后问题 时间复杂度为 O(n!) 51. N 皇后 经典做法 #include <string> #include <iostream> #include <vector> #include <unordered_set> using namespace std; class Solution
阅读全文
posted @ 2024-10-06 21:07 _Sylvan
阅读(40)
评论(0)
推荐(0)
嵌套类递归
摘要: 嵌套类递归 都需要一个全局变量记录当前正在处理的位置 基础计算器 III 含有嵌套的表达式求值,时间复杂度 O(n) #include <iostream> #include <string> #include <vector> using namespace std; class Solution
阅读全文
posted @ 2024-10-06 15:44 _Sylvan
阅读(41)
评论(0)
推荐(0)
2024年10月5日
经典递归
摘要: master 公式 所有子问题规模相同的递归才能用master公式:T(n) = a * T(n / b) + O(n ^ c),a、b、c为常数 a 表示递归的次数也就是生成的子问题数,b 表示每次递归是原来的 1/b 之一个规模,O(n ^ c) 表示分解和合并所要花费的时间之和。 若 log(
阅读全文
posted @ 2024-10-05 21:47 _Sylvan
阅读(19)
评论(0)
推荐(0)
2024年9月30日
构建前缀信息解决子数组问题
摘要: 构建前缀信息解决子数组问题 303. 区域和检索 - 数组不可变 #include <vector> using namespace std; class NumArray { public: // 前缀和数组 vector<int> prefixSum; NumArray(vector<int>
阅读全文
posted @ 2024-09-30 21:58 _Sylvan
阅读(22)
评论(0)
推荐(0)
二叉树高频题(下)
摘要: 二叉树高频题(下) 236. 二叉树的最近公共祖先 using namespace std; struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(nullptr), ri
阅读全文
posted @ 2024-09-30 01:33 _Sylvan
阅读(17)
评论(0)
推荐(0)
2024年9月29日
二叉树高频题(上)
摘要: 二叉树高频题(上) 102. 二叉树的层序遍历 #include <vector> #include <iostream> #include <algorithm> #include <queue> using namespace std; struct TreeNode { int val; Tr
阅读全文
posted @ 2024-09-29 20:40 _Sylvan
阅读(24)
评论(0)
推荐(0)
2024年9月28日
链表高频题
摘要: 链表高频题 160. 相交链表 #include <vector> #include <iostream> #include <algorithm> struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(N
阅读全文
posted @ 2024-09-28 23:30 _Sylvan
阅读(22)
评论(0)
推荐(0)
数据结构设计
摘要: 数据结构设计 设计有setAll功能的哈希表 加时间戳 #include <vector> #include <iostream> #include <algorithm> #include <unordered_map> using namespace std; // <key, <val, ti
阅读全文
posted @ 2024-09-28 18:43 _Sylvan
阅读(28)
评论(0)
推荐(0)
2024年9月27日
堆
摘要: 堆 912. 排序数组 #include <vector> using namespace std; class Solution { public: // 自上而下调整大顶堆,O(logn) void adjustHeap(vector<int> &nums, int len, int curIn
阅读全文
posted @ 2024-09-27 12:10 _Sylvan
阅读(23)
评论(0)
推荐(0)
2024年9月26日
前缀树
摘要: 前缀树 在计算机科学中,trie,又称前缀树或字典树,是一种有序树,用于保存关联数组,其中的键通常是字符串。与二叉查找树不同,键不是直接保存在节点中,而是由节点在树中的位置决定。一个节点的所有子孙都有相同的前缀,也就是这个节点对应的字符串,而根节点对应空字符串。一般情况下,不是所有的节点都有对应的值
阅读全文
posted @ 2024-09-26 22:03 _Sylvan
阅读(31)
评论(0)
推荐(0)
快速选择
摘要: 快速选择 215. 数组中的第K个最大元素 时间复杂度 O(n),空间复杂度 O(1) #include <vector> #include <cstdlib> #include <ctime> using namespace std; class Solution { public: int qu
阅读全文
posted @ 2024-09-26 12:18 _Sylvan
阅读(23)
评论(0)
推荐(0)
快排
摘要: 快排 快速排序的最优情况是每一次取到的元素都刚好平分整个数组,T(n) = 2 * T(n/2) + O(n),由 master 公式得到算法的时间复杂度为 O(nlogn),空间复杂度为 O(logn) 最坏情况是数组本身有序,每一次取到的元素都是待排序列中的最值,效果相当于冒泡排序。这种情况下,
阅读全文
posted @ 2024-09-26 11:01 _Sylvan
阅读(54)
评论(0)
推荐(0)
归并分治
摘要: 归并排序 912. 排序数组 #include <iostream> #include <vector> using namespace std; class Solution { public: // 分治-治 void merge(vector<int> &arr, int left, int
阅读全文
posted @ 2024-09-26 08:42 _Sylvan
阅读(26)
评论(0)
推荐(0)
2024年9月24日
一维差分和等差数列差分
摘要: 一维差分 不支持边操作边查询 对于数组 a,定义其差分数组(difference array)为 i = 0 时,d[i] = a[0]; i > 0 时,d[i] = a[i] - a[i-1]; 性质 1:从左到右累加 d 中的元素,可以得到数组 a。 性质 2:如下两个操作是等价的。 区间操作
阅读全文
posted @ 2024-09-24 14:56 _Sylvan
阅读(51)
评论(0)
推荐(0)
上一页
1
···
14
15
16
17
18
19
20
21
22
···
33
下一页
公告