自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 C++lower_bound函数

贴一下源码 template <class ForwardIterator, class T> ForwardIterator lower_bound (ForwardIterator first, ForwardIterator last, const T& val) { ForwardIterator it; iterator_traits<ForwardIterator>::difference_type count, step; count

2022-01-29 16:00:58 2882

原创 vector<pair<int,int>>的一些问题

众所周知,往vector中插入元素有两个函数 push_back()和emplace_back() 他们俩的底层实现原理是不同的 push_back() 向容器尾部添加元素时,首先会创建这个元素,然后再将这个元素拷贝或者移动到容器中(如果是拷贝的话,事后会自行销毁先前创建的这个元素);而 emplace_back() 在实现时,则是直接在容器尾部创建这个元素,省去了拷贝或移动元素的过程。 添加pair对时,下列两个方法都可以 for (int i = 0; i < n; ++i.

2022-01-27 11:36:16 1396

原创 二分查找边界问题

//二分查找的边界值问题 //查找左边界值 int left_bound(int[] nums, int target) { int left = 0, right = nums.length - 1; // 搜索区间为 [left, right] while (left <= right) { int mid = left + (right - left) / 2; if (nums[mid] < target) { .

2022-01-20 22:03:57 370

原创 (五)二叉树的各种遍历

递归遍历 //递归 先序遍历 void traverse1(TreeNode *root){ if(root==nullptr) return; /* 对节点的操作 */ traverse1(root->left); traverse1(root->right); } //递归 中序遍历 void traverse2(TreeNode *root){ if(root==nullptr) return; trav

2021-10-26 20:09:11 191

原创 算法学习笔记(四)链表

(一)哈希表 unordered_map和unsorted_set unordered_map Key-> Value unordered_set Key hastable中的东西,若为基础类型,内部按值传递,否则按引用传递(内存占用为这个东西内存地址的大小)如装入hashtable的东西为struct,记录内存地址作为key 如 nodeA=new Node(1); nodeB=new Node(1) 两个不一样,因为内存地址不一样 可以认为hashtable增删改查都为常数时间的操.

2021-10-09 20:48:41 204

原创 算法学习笔记(二)归并排序、快速排序

(一)归并排序 (1)求数组中的最大值 #include<bits/stdc++.h> using namespace std; class GetMax { public: static int GetArrMax(vector<int> arr, int L, int R) { if(L==R) return arr[L]; int mid=(L+R)>>1; int LeftMax=.

2021-09-25 20:41:52 271

原创 算法学习笔记(一) 复杂度与简单排序算法

(一)复杂度 时间复杂度:忽略小项 只关注最大项 忽略最大项的常数部分 空间复杂度:一般关注辅助空间复杂度 (二) 排序 (1) 选择排序 时间复杂度O(n^2) 辅助空间复杂度O(1) #include<bits/stdc++.h> using namespace std; int main() { vector<int> nums; nums={3,4,7,2,3,7,2,1}; // 0个或者一个元素 //不用进行排序 if(

2021-09-15 22:24:54 381 4

空空如也

空空如也

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

TA关注的人

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