使用三个线程交替打印ABC
摘要://用的是线程、互斥锁、条件变量 #include <iostream> #include <thread> #include <mutex> #include <condition_variable> using namespace std; mutex _mutex; //定义锁变量 condi
阅读全文
posted @
2024-03-29 11:35
孜孜不倦fly
阅读(62)
推荐(0) 编辑
快速次幂
摘要:题目: 拿到一个数组,每次操作会将除了第x个元素之外的元素都翻倍,一共操作q次,求操作结束后所有元素之和 int main() { int n, q, xi; const long long mod = 1e9 + 7; cin >> n >> q; vector<long long> a(n);
阅读全文
posted @
2024-03-18 15:07
孜孜不倦fly
阅读(5)
推荐(0) 编辑
合并 K 个升序链表
摘要:题目: class Solution { public: //合并两个升序链表 ListNode* mergetwo(ListNode* l1, ListNode* l2){ if(!l1 || !l2) return l1 ? l1 : l2; ListNode* dummy = new List
阅读全文
posted @
2024-03-13 15:44
孜孜不倦fly
阅读(6)
推荐(0) 编辑
K 个一组翻转链表
摘要:题目: struct ListNode{ int val; ListNode* next; ListNode(): val(0), next(nullptr) {} ListNode(int _val): val(_val), next(nullptr) {} ListNode(int _val,
阅读全文
posted @
2024-03-12 22:38
孜孜不倦fly
阅读(3)
推荐(0) 编辑
排序链表(自底向上归并排序)
摘要:题目: 时间复杂度:O(nlogn),空间复杂度:O(1) struct ListNode{ int val; ListNode* next; ListNode(): val(0), next(nullptr) {} ListNode(int _val): val(_val), next(nullp
阅读全文
posted @
2024-03-11 21:24
孜孜不倦fly
阅读(10)
推荐(0) 编辑
数组中的第K个最大元素
摘要:题目: //方法一,利用优先队列小顶堆greater(大顶堆是less) class Solution { public: int findKthLargest(vector<int>& nums, int k) { priority_queue<int, vector<int>, greater<
阅读全文
posted @
2024-03-10 21:25
孜孜不倦fly
阅读(9)
推荐(0) 编辑
判断链表回文
摘要:题目: //方法一,空间复杂度O(n) class Solution { public: bool isPalindrome(ListNode* head) { vector<int> nums; //放进数组后用双指针判断 ListNode* cur = head; while(cur){ num
阅读全文
posted @
2024-03-10 21:02
孜孜不倦fly
阅读(6)
推荐(0) 编辑
和为K的子数组
摘要:题目: 使用前缀和的方法可以解决这个问题,因为我们需要找到和为k的连续子数组的个数。通过计算前缀和,我们可以将问题转化为求解两个前缀和之差等于k的情况。 假设数组的前缀和数组为prefixSum,其中prefixSum[i]表示从数组起始位置到第i个位置的元素之和。那么对于任意的两个下标i和j(i
阅读全文
posted @
2024-03-07 22:17
孜孜不倦fly
阅读(66)
推荐(0) 编辑
C++ LRU缓存
摘要:题目: //构建双向链表的节点结构(要有两个构造函数) struct Node{ int key, val; Node* pre; Node* next; Node():key(0), val(0), pre(nullptr), next(nullptr) {} Node(int _key, int
阅读全文
posted @
2024-03-06 21:27
孜孜不倦fly
阅读(13)
推荐(0) 编辑
C++实现memcpy和memmove(含调试程序)
摘要:#include <iostream> #include <string> using std::cout; using std::endl; void* mymencpy(void* dest, void* src, size_t num) { char* d = (char*)dest; cha
阅读全文
posted @
2024-02-07 13:05
孜孜不倦fly
阅读(22)
推荐(0) 编辑
C++实现直接插入排序、冒泡排序、快速排序、选择排序(含调试程序)
摘要:#include<iostream> #include<fstream> #include<string> #include<vector> #include <algorithm> using namespace::std; class Solution { public: //直接插入排序(插到
阅读全文
posted @
2024-01-29 23:36
孜孜不倦fly
阅读(53)
推荐(0) 编辑
二叉排序树删除节点
摘要:**前驱替换法** 用被删除节点左子树最右边的节点的值来替换被删除节点  上图删除了节点11
阅读全文
posted @
2023-07-17 15:36
孜孜不倦fly
阅读(13)
推荐(0) 编辑