会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
cotoyo25
博客园
首页
新随笔
联系
订阅
管理
2022年8月24日
c++单例模式
摘要: 单例模式的意图:一个类只能有一个实例。 //单例模式: 懒汉模式:在需要时才创建。需要考虑线程安全。 饿汉模式:系统一运行就构造初始化,不需要考虑线程安全。 //以下是懒汉模式: //非线程安全版本 1 class Singleton{ 2 private: 3 Singleton(); 4 Sin
阅读全文
posted @ 2022-08-24 10:16 coyote25
阅读(78)
评论(0)
推荐(0)
2022年6月29日
二分模板
摘要: using namespace std; //二分模板 class Solution { public: vector<int> searchRange(vector<int>& nums, int target) { vector<int> ans={-1,-1}; int n = nums.si
阅读全文
posted @ 2022-06-29 14:28 coyote25
阅读(30)
评论(0)
推荐(0)
2022年6月20日
线段树-区间求和-动态开点-Node版本
摘要: 1 #include <bits/stdc++.h> 2 #include <unordered_map> 3 using namespace std; 4 //线段树成,node版本; 5 class Node{ 6 public: 7 Node * left; 8 Node * right; 9
阅读全文
posted @ 2022-06-20 14:14 coyote25
阅读(49)
评论(0)
推荐(0)
2022年6月19日
树状数组
摘要: #include <bits/stdc++.h> #include <unordered_map> //数状数组; using namespace std; class Solution { private: int lowbit(int x) { return x & -x; } vector<i
阅读全文
posted @ 2022-06-19 15:58 coyote25
阅读(23)
评论(0)
推荐(0)
2022年6月6日
线段树——区间求和
摘要: #include <bits/stdc++.h> using namespace std; //以下是线段树的模板,让区间查询和修改的时间复杂度到O(lgn); class XianDuanTree{ private: vector<int> arr; vector<int> tree; publi
阅读全文
posted @ 2022-06-06 13:25 coyote25
阅读(91)
评论(0)
推荐(0)
2022年5月18日
手写UniquePtr
摘要: UniquePtr:独占所有的对象。 1 #include <iostream> 2 3 4 using namespace std; 5 template<typename T> 6 class UniquePtr{ 7 private: 8 T * ptr; 9 //non-copy 10 Un
阅读全文
posted @ 2022-05-18 14:47 coyote25
阅读(110)
评论(0)
推荐(0)
手写share_ptr
摘要: share_ptr:c++11引入的智能指针。是模板类,允许多个指针指向同一个对象。通过判断引用计数的值,来决定何时释放动态内存。 1.用nullptr构造时,引用计数为0; 2.用非nullptr构造时,引用计数为1; 3.拷贝一个share_ptr,引用计数会加1:如拷贝构造,share_ptr
阅读全文
posted @ 2022-05-18 13:50 coyote25
阅读(211)
评论(0)
推荐(0)
2022年5月17日
正则表达式匹配
摘要: #include <bits/stdc++.h> using namespace std; //正则匹配 class Solution{ public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @
阅读全文
posted @ 2022-05-17 11:40 coyote25
阅读(30)
评论(0)
推荐(0)
2022年5月6日
贪心放灯
摘要: 暴力递归: 1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 class Solution { 6 public: 7 //定义:index之后的位置选择还没做,前面的已经做了,light存放已经放过灯的位置; 8 //返回能够照亮所有位
阅读全文
posted @ 2022-05-06 16:40 coyote25
阅读(24)
评论(0)
推荐(0)
打表找规律
摘要: #include <bits/stdc++.h>using namespace std;class Solution{public: string winner1(int n ){ if(0<=n && n<= 4) return (n==0 ||n==2 )?"hou":"xian"; int b
阅读全文
posted @ 2022-05-06 11:29 coyote25
阅读(35)
评论(0)
推荐(0)
下一页
公告