做题笔记
做题笔记
竹林观月
这个作者很懒,什么都没留下…
展开
-
做题笔记18(自然数的拆分问题)
三、总结1.枚举可能性,进行回溯。部分流程如下图2.在深度搜索完成,将进行回溯前,要先弹出该节点。原创 2022-06-02 09:59:44 · 90 阅读 · 0 评论 -
做题笔记17(实现生产者消费者进程)
文章目录一、题目二、相关知识1)共享内存0.以下函数所用的头文件1.shmget()函数----用于创建共享内存2.shmat()函数----用于建立映射3.shmdt()函数----用于解除映射4.shmct()函数2)POSIX信号量0.头文件1.sem_open()函数----用于创建或打开一个信号量2.sem_wait()函数----用于进行p操作3.sem_post()函数----用于进行v操作4.sem_getvalue()函数和sem_unlink()函数三、代码一、题目二、相关知识1原创 2022-05-07 22:00:32 · 980 阅读 · 1 评论 -
做题笔记16(逆序对)
文章目录一、题目二、2-路归并排序三、逆序对一、题目二、2-路归并排序因题目提示可以在归并排序的过程中进行统计,故先回顾归并排序。归并排序:将有n个元素的初始序列看作n个子序列,两两归并,得到⌈n2⌉\lceil \frac{n}{2} \rceil⌈2n⌉个长度为2或1的有序子序列,再两两归并,重复至得到一个长度为n的有序序列为止。核心操作:将一维数组中前后相邻的两个有序序列归并为一个有序序列。void merge(int* a, int low, int mid, int high)原创 2022-04-24 22:12:36 · 264 阅读 · 0 评论 -
做题笔记15(并发程序设计)
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档文章目录一、创建1层10个子进程1.题目2.代码3.思路二、创建10层1个子进程1.题目2.代码3.思路:三、创建3层完全二叉树式进程1.题目2.代码四、总结1.gdb调试多进程2.gdb一些常用指令一、创建1层10个子进程1.题目2.代码#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/t.原创 2022-04-11 17:52:47 · 674 阅读 · 0 评论 -
做题笔记1(两数之和)
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档文章目录前言一、哈希表定义二、关于该题的思路三、实现代码总结前言今天试着写了力扣题库第一题,接触了哈希表法。题目一、哈希表定义 散列表(Hash table,也叫哈希表),是根据关键码值(Key value)而直接进行访问的数据结构。也就是说,它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度。这个映射函数叫做散列函数,存放记录的数组叫做散列表。二、关于该题的思路首先把数组里每一个元素作为ke原创 2021-06-18 16:46:44 · 203 阅读 · 1 评论 -
做题笔记2(两数相加)
文章目录一、题目二、思路1234三、用c++实现迭代法一、题目Leetcide第二题二、思路1引入carry,默认为0。2当两个链表处于同一位的值都不为零时,两数相加再加上carry的值,若为个位数将该数赋予该节点;若为十位数,则还需将该数的十位赋予carry。3若两个链表中的一个在该节点处为空,则用0代替。4两链表都为空时,若carry的值不为零,需在尾部再插入carry的值。三、用c++实现迭代法class Solution {public: ListNode*原创 2021-08-07 23:29:37 · 80 阅读 · 0 评论 -
做题笔记3(二分查找)
文章目录题目一、顺序查找二、二分查找1.代码2.数组的下标越界和内存溢出题目https://leetcode-cn.com/problems/binary-search/一、顺序查找class Solution {public: int search(vector<int>& nums, int target) { int n = nums.size(); int a = -1; for(int i=0;i<n;i原创 2021-08-20 23:19:08 · 63 阅读 · 0 评论 -
做题笔记4(第一个错误的版本,搜索插入位置)
文章目录题目一、题目一1.代码2.其他二、题目二1.代码2.其他题目第一个错误的版本搜索插入位置一、题目一1.代码// The API isBadVersion is defined for you.// bool isBadVersion(int version);class Solution {public: int firstBadVersion(int n) { int min=1; int max=n; while(mi原创 2021-08-28 22:17:05 · 46 阅读 · 0 评论 -
做题笔记5(有序数组的平方)
文章目录题目一.代码1)使用冒泡排序,会超出时间限制。2)使用sort函数3)双指针法二.其他1)关于sort函数题目有序数组的平方一.代码1)使用冒泡排序,会超出时间限制。class Solution {public: vector<int> sortedSquares(vector<int>& nums) { int n = nums.size(); vector<int> newnums(n, 0); for (int i = 0原创 2021-09-03 17:19:17 · 52 阅读 · 0 评论 -
做题笔记6(判断矩形是否重叠)
文章目录一、题目二、解决方案1.直接法2.反向一、题目二、解决方案1.直接法1)代码#include<iostream>#include<stdio.h>#include <iomanip>#include<math.h>using namespace std;class Rect{private: int x1; int x2; int y1; int y2;public: Rect(int a, int b, int原创 2021-09-18 17:34:33 · 101 阅读 · 0 评论 -
做题笔记7(顺序表的连续操作,合并操作)
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档文章目录一、DS顺序表--连续操作1.错误案例2.正确案例3.分析二、DS顺序表--合并操作1.错误案例2.正确案例3.分析总结一、DS顺序表–连续操作1.错误案例#include<iostream>#include<stdio.h>#include <iomanip>#include<math.h>#include<unordered_set>using na原创 2021-09-24 16:18:07 · 137 阅读 · 0 评论 -
做题笔记8(单链表删除重复元素,找到数组的中间元素)
文章目录一、 DS单链表—删除重复元素1.题目2.解决方案3.反思一、 DS单链表—删除重复元素1.题目2.解决方案#include<iostream>using namespace std;#define ok 0#define error -1class ListNode{public: int data; ListNode* next; ListNode() { next = NULL; }};class LinkList{public:原创 2021-09-28 19:00:02 · 265 阅读 · 0 评论 -
做题笔记9(组队列)
文章目录一、题目二、代码总结一、题目二、代码#include <iostream>#include<queue>using namespace std;int whi(int s, int** a, int m, int n){ int w = -1; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (s == a[i][j]) { w =原创 2021-10-15 18:38:27 · 55 阅读 · 0 评论 -
做题笔记10(计算一个串的最长真前后缀,最长重复子串)
文章目录一、计算一个串的最长的真前后缀1.题目2.解答3.反思1.reverse()2.substr()3.字符串复制二、最长重复子串1.题目2.解答3.反思1.comapre()2.find()3.拓展一、计算一个串的最长的真前后缀1.题目2.解答#include<iostream>#include<string>#include <algorithm> using namespace std; string back(string str){原创 2021-10-23 17:36:03 · 276 阅读 · 0 评论 -
做题笔记11(KMP算法)
文章目录一、题目二、解答一(根据模板)三、解法二总结一、题目二、解答一(根据模板)#include <iostream>#include <string> using namespace std; class myString {private: string mainstr; int size; void GetNext(string p, int next[]) { next[0] = -1; n原创 2021-10-30 18:24:49 · 70 阅读 · 0 评论 -
做题笔记12(最大子数组和)
文章目录一、题目二、代码三、总结1.[for-each](https://blog.csdn.net/Das20pct/article/details/47440291?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163948649316780261998262%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=16原创 2021-12-19 23:46:06 · 178 阅读 · 0 评论 -
做题笔记13(无重复字符的最长子串)
文章目录题目代码总结题目代码class Solution {public: int lengthOfLongestSubstring(string s) { int size = s.length(); int len = 0; int start = 0; int end = 0; int result = 0; while (end < size) {原创 2022-01-20 21:52:14 · 366 阅读 · 0 评论 -
做题笔记14(有效的字母异位词)
文章目录一、题目二、代码三、总结一、题目有效的字母异位词二、代码class Solution { public boolean isAnagram(String s, String t) { char[] str1 = s.toCharArray(); char[] str2 = t.toCharArray(); Arrays.sort(str1); Arrays.sort(str2); return Arra原创 2022-02-14 21:32:17 · 234 阅读 · 0 评论