自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(36)
  • 收藏
  • 关注

原创 C艹11以及开发经验

1.auto和decltype关键字// 用auto告知编译器模板的返回类型需要自动推导// 用decltype(expression)告知编译器返回类型根据expression推导// -> decltype(expression) 这种表示法叫做尾置返回类型template <typename T, typename U>auto f(T t, U u) -> decltype(t + u){return t + u;}// C++14template &lt

2022-05-19 20:33:14 370 1

原创 protobuf使用

谷歌protonbuf 使用:boost也有内置序列化的类1.序列化的过程:·发送端原始数据->序列化->特殊格式的字符串发送该字符串·接收端接受数据特殊格式字符串->发序列化->得到原始数据对原始数据处理2.使用步骤· 准备数据:类或者结构体· 创建一个新文件 xx.proto· 通过命令protoc将xx.proto转化成一个C++类,生成头文件和cpp文件·直接使用这个类:里面存在对数据操作的api:​ ·读操作: 方法名字 变量名()​ ·

2022-04-16 16:05:42 612

原创 atomic简单用法

#pragma region atomic#include<atomic>#include<thread>#include<mutex>int g_myCount = 0;atomic<int> g_myCount1 = 0;//atomic<>无 *= /= %=等操作mutex mu;//无锁,随机值//void myThread()//{// for (int i = 0; i < 100000;

2022-04-10 15:42:01 475

原创 C艹智能指针解剖

class Wife;class Husband{public: void setWife(const shared_ptr<Wife>& wife) { this->myWife = wife; cout << "myWife's use_count" << myWife.use_count() << endl; } ~Husband() { cout

2022-04-08 14:06:12 241

原创 C艹关键字解析

1.decltype作用于变量直接得到变量的类型;②作用于表达式,结果是左值的表达式得到类型的引用,结果是右值的表达式得到类型;③作用于函数名会得到函数类型,不会自动转换成指针。a. decltype(val) 会返回val的类型const int a = 10;decltype(a) b = 19;b. decltype(expr)int i = 42, *p = &i, &r = i;// r + 0是一个表达式// 算术表达式返回右值// b是一个int类型

2022-04-05 20:52:56 319

原创 C艹炫技,leet49 字母异位字符串分组

class Solution {public: vector<vector<string>> groupAnagrams(vector<string>& strs) { // 自定义对 array<int, 26> 类型的哈希函数 //炫技 auto arrayHash = [fn = hash<int>{}] (const array<int, 26>& arr

2022-04-05 16:00:47 160

原创 STL解决算法问题

struct stHelper{bool operator()(const char& a,const char& b)const{return a == ’ ’ && b == ’ ';}};bool isOdd(int x){return x % 2 != 0;}int main(){//1.字符串去重 unique方法string s = “a b c”;auto last = unique(s.begin(), s.end(), st

2022-04-05 10:27:40 61

原创 C艹开源可读项目整理

1.Nanolog 基于std::atomic实现的高性能无锁日志(如何实现无锁多线程,如何保证数据同步)2.muduo事件库: https://github.com/wlgq2/uv-cpp3.RPC:Remote Procedure Call远程过程调用:底层的网络通信基于c++11设计,更加方便理解。中间的Json设计,基于json-tutorials 改进,也是rapidJson的简化https://github.com/szza/jrpc4.C++微内核操作系统:学习doxygen,

2022-04-01 16:08:33 1393

原创 字符串分割成回文子串

vector<vector<string>> ans;vector<string> res;void dfs(string s);vector<vector<string>> partition(string s) { dfs(s); return ans;}void dfs(string s){ if ("" == s) { ans.emplace_back(res);

2022-03-07 14:50:07 116

原创 STL总结

1.reserve和resize什么区别、resize(n):调整容器的长度大小,使其能容纳n个元素。如果n小于容器当前的size,则删除多出来的元素,否则,添加采用值初始化的元素。reserve(n,t):多一个参数t,将所有新添加的元素初始化为t。2、reserve(n):预分配n个元素的存储空间。 capacity:容量(容器当前拥有的元素个数) size:长度(容器在必须分配新存储空间之前可以存储的元素总数)3、resize->size:调用resize(n),容器的siz

2022-03-01 23:31:02 58

原创 C艹中string与cahr *互转

char pp[10] = "shanrui"; string pps((char*)pp, 10); cout << pps << endl; int n = pps.size(); char* stc = new char[n + 1]; memcpy(stc, pps.c_str(), n);

2022-03-01 14:25:41 111

原创 C艹多线程循环打印队列或者数字

直接上代码!!!```cpp#include <cstdio>#include<iostream>#include<mutex>#include<condition_variable>#include<queue>using namespace std;class A{private: mutex mu; condition_variable cv; mutex mu1; condition

2022-03-01 11:05:59 196

原创 leetcode前缀最小值

刷题

2022-02-27 15:03:56 163

原创 合并K个连续链表

// algorithm.cpp : 定义控制台应用程序的入口点。#include "stdafx.h"#include<iostream>#include<vector>#include<queue>using namespace std;struct ListNode{ int val; ListNode* next; ListNode(int x) :val(x){}};ListNode* makeList(vector<int&g

2022-02-24 16:41:44 297

原创 C++中创建txt不消除原来的内容

#include<fstream>void fLog() { fstream OutFile; OutFile.open("out2.txt", ios::binary | ios::in | ios::out | ios::app);//|ios::app);//app表示追加方式打开 OutFile << "hello3" << endl; OutFile.close();}

2022-02-21 22:42:05 1454

原创 K个一组反转链表

class Solution {public: // 翻转一个子链表,并且返回新的头与尾 pair<ListNode*, ListNode*> myReverse(ListNode* head, ListNode* tail) { ListNode* prev = tail->next; ListNode* p = head; while (prev != tail) { ListNode* nex

2022-02-20 21:15:53 185

原创 C++中using的四大用法总结

1.使用名称空间,如using namespace std;2.使用别名,using 类型别名=原类型,如using uint=unsigned int;uint i=0; 3.当一个派生类私有继承基类时,基类的public和protected数据成员在派生类中是private的形式,如果想让这些继承而来的数据成员作为public或者protected成员,可以用using来重新声明。using声明语句中名字的访问权限由该using声明语句之前的访问说明符决定。class Basic{

2022-02-16 11:40:59 10593

原创 C++内存拷贝常用函数

/*memset void memset(void s, int c, size_t n);主要应用是初始化某个内存空间。用是在一段内存块中填充某个给定的值,一般为0,它对较大的结构体或数组进行清零操作的一种最快方法memcpy extern memcpy(char dest, const char src, size_t count);是用于copy源空间的数据到目的空间中。strcpy extern char *strcpy(char *dest,char *src);

2022-02-16 11:02:49 1853

原创 链表反转——递归

ListNode* reverseList(ListNode* head) { if(!head || !head->next){ return head; } ListNode* temp=reverseList(head->next); head->next->next=head; head->next=nullptr; return temp; }

2022-02-15 22:43:26 529 1

原创 第K大的数

2022-02-11 22:32:33 260

原创 【无标题】STL常用函数集合

2022-02-09 22:23:37 239

原创 【无标题】最长快乐字符串leetcode总结

如果字符串中不含有任何 'aaa','bbb' 或 'ccc' 这样的字符串作为子串,那么该字符串就是一个「快乐字符串」。给你三个整数 a,b ,c,请你返回 任意一个 满足下列全部条件的字符串 s:s 是一个尽可能长的快乐字符串。s 中 最多 有a 个字母 'a'、b 个字母 'b'、c 个字母 'c' 。s 中只含有 'a'、'b' 、'c' 三种字母。如果不存在这样的字符串 s ,请返回一个空字符串 ""。```cppclass Solution {public: stri

2022-02-07 20:44:36 6005

原创 二叉树的中序遍历

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} *

2022-02-01 19:16:41 58

原创 二叉树前序遍历迭代

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} *

2022-02-01 19:04:34 67

原创 二叉树的后序遍历迭代

在这里插入代码片/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullp

2022-02-01 18:07:53 668 1

原创 【无标题】unordered_map方法

```cppint singleNumber(vector<int>& nums) { unordered_map<int, int> freq; for (int num: nums) { ++freq[num];//哈希表添加元素 } int ans = 0; for (auto [num, occ]: freq) { //学会这种遍历的方法 .

2022-01-30 20:20:18 319

原创 链表的归并排序

/**Definition for singly-linked list.struct ListNode {int val;ListNode *next;ListNode() : val(0), next(nullptr) {}ListNode(int x) : val(x), next(nullptr) {}ListNode(int x, ListNode *next) : val(x), next(next) {}};/class Solu.

2022-01-23 16:04:11 612

原创 查询数组中只出现一次的数字,其余出现两次

可使用异或运算。异或运算有以下三个性质。任何数与0异或都是它自己任何数与自己异或都是0异或满足交换和集合率public int singleNumber(int[] nums) { int single = 0; for (int num : nums) { single ^= num; } return single; }...

2022-01-19 23:37:13 138

原创 leetcode190

被包围的区域,从边界条件入手,深入内部:class Solution {public: int m,n; void solve(vector<vector<char>>& board) { n =board.size(); if(n==0){ return ; } m=board[0].size(); for(int i=0;i<n;i++){

2022-01-17 23:52:54 149

原创 【无标题】129. 求根节点到叶节点数字之和

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} *

2022-01-16 20:14:23 265

原创 数组移位leetcode189

记住assign()用法```cppvoid rotate(vector<int>& nums, int k) { int n=nums.size(); vector<int> newArr(n); for(int i=0;i<n;++i){ newArr[(i+k)%n]=nums[i]; } nums.assign(newArr.begin(),newArr

2022-01-11 23:18:34 165

原创 leetcode 77 (1-n)k个数字组合

class Solution {public:vector<vector> combine(int n, int k) {vector<vector> ans;vector res;dfs(n,k,res,ans,1);return ans;}void dfs(int n,int k,vector& res,vector<vector>& ans,int idx){if(res.size()==k){ans.push_back(res)

2022-01-02 10:15:46 111

原创 【无标题】

数组总和leetcode输入:candidates = [2,3,6,7], target = 7输出:[[2,2,3],[7]]class Solution {public:vector<vector> combinationSum(vector& candidates, int target) {vector<vector> res;vector temp;sort(candidates.begin(),candidates.end());int num

2021-12-27 23:54:14 225

原创 【无标题】

前言设计模式一直是学习的一道坎,出这个专题一方面想提升自己,另一方面还是想帮助跟我一样的前端小白更好理解这部分的知识。今天先介绍比较常见的构造器模式和工厂模式,文章还是结合场景来展开,就不干巴巴讲概念,毕竟也没书上讲的好(菜鸡去世)。开篇当然,还是要先介绍什么是设计模式。“诶,你这不是不讲概念嘛。”“确实,但这不跟相亲一样嘛,上来就说家里俩套房不合适吧。”首先来说, 设计模式是一种思想,它是软件开发人员在软件开发过程中面临的一般问题的解决方案。这些解决方案是众多软件开发人员经过相当长的一段时间的

2021-12-20 23:27:06 164

原创 2021-09-27

最长无重复的字串:abcabcaa=>3 刷题1int lengthOfLongestSubstring(string s) {// 哈希集合,记录每个字符是否出现过unordered_set occ;int n = s.size();// 右指针,初始值为 -1,相当于我们在字符串的左边界的左侧,还没有开始移动int rk = -1, ans = 0;// 枚举左指针的位置,初始值隐性地表示为 -1for (int i = 0; i < n; ++i) {if (i !=

2021-09-27 21:41:19 53

原创 HTML学习

1.请求报文-常用请求方法GET:用于请求访问已经被URI识别的资源,可以通过URL传参给服务器。没有body体,当需要传递参数给服务器时,参数会被携带在URI中,故而请求的传参长度有限制,而post长度没有限制,post有body;请求的参数只能是ASCII码,中文需要URL编码,而POST没有限制。POST:用于传输信息给服务器。PUT:传输文件,报文主体中包含文件内容,保存到对应的URI位置。DELETE:删除对应的URI位置的文件HEAD:获取报文首部,不返回报文主体,常用于验证URI是否

2021-09-10 16:30:13 82

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除