- 博客(25)
- 收藏
- 关注
原创 【二叉树复习
二叉树: 这是求最近祖先算法 #include<iostream> using namespace std; const int maxn=51; struct Node{ int left;int right; }nodes[maxn]; int LCA(int root,int k1,int k2){ if(root==-1) return -1;//一旦空 返回-1 然后上一层判断 if(root==k1||root==k2) return root;//遇见匹配的
2022-06-02 11:14:35
120
原创 复习排序。。。(今天效率好低啊)
#算法的稳定性: 存在多个具有相同排序码的记录,排序后这些记录的相对次序保持不变 #理想的空间效率: 算法执行期间所需要的辅助空间与待排序的顺序无关 折半插入排序 快速排序:
2022-06-02 00:03:51
140
原创 duiduidui
// 2099. `找到和最大的长度为 K 的子序列` class Solution { class Pair{ public: int val; int idx; Pair() {} Pair(int v, int i) : val(v), idx(i) {} bool operator < (const Pair& o) const { return v
2022-05-29 21:04:09
187
原创 heibang
heibang #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <stack> #include <queue> #include <map> #include <cmath> #define INF 0x3f3f3f3f using namespace std; typedef l
2022-05-13 00:29:08
159
原创 记录改bug的第n天
虫子的生活 虫子的生活 #include<iostream> using namespace std; const int N = 2010; int pre[N], r[N];//pre存储i的父节点 r存储i和父节点的关系,0表示i和父节点是同性,1表示是异性 void init(int n) { for (int i = 0; i <= n; i++){ pre[i] = i;//自己为自己的父节点 r[i] = 0;//自己与自己是同性 } } int f
2022-05-06 14:23:38
217
原创 第一个值得思考
找出可行的回文串个数 class Solution { public: bool canConstruct(string s, int k) { int hash[26]; int n = s.length(); memset(hash, 0, sizeof(hash)); for(int i = 0; i < n; i++) { hash[s[i] - 'a']++; //(1) }
2022-05-04 22:47:54
101
原创 03----5.1
(1) class Solution { public: vector<int> sortedSquares(vector<int>& nums) { vector<int>res; for(int num:nums){ res.push_back(num*num); } stable_sort(res.begin(),res.end()); return res; } }; 时间复杂度:O(
2022-05-03 22:37:31
339
原创 栓3-----
题目 class Solution { public: int numSpecial(vector<vector<int>>& mat) { int rows=mat.size(); int cols=mat[0].size(); int rowcnt[rows]; int colcnt[cols]; memset(rowcnt,0,sizeof(rowcnt)); memset(colcnt,0,sizeof(colc
2022-04-30 21:43:47
494
原创 数据结构每日复习之链表1
多项式的加减乘除 题目 # include<iostream> # include<algorithm> using namespace std; struct LNode{ int num; int pow; struct LNode * next; }; void ListInsert(LNode * pHead, int a, int b) { LNode * p = new LNode; p->num = a; p->pow = b; p->n
2022-04-29 20:34:16
774
原创 栓2-----
唯一元素的 和 class Solution { public: int sumOfUnique(vector<int>& nums) { int ans=0; int cnt[110]; memset(cnt,0,sizeof(cnt)); for(int i=0;i<nums.size();i++){ cnt[nums[i]]++; } for(int
2022-04-29 18:43:13
234
原创 栓1-------
class Solution { public: bool isPowerOfTwo(int n) { return n > 0 && (n & (n-1))==0; } }; n&n-1==0 时 n为2的倍数 class Solution { public: bool isPowerOfTwo(int n) { return n > 0 && (n & -n) == n;
2022-04-28 23:15:38
134
原创 第一天栓0
解压缩编码列表 class Solution { public: vector<int> decompressRLElist(vector<int>& nums) { vector<int>res; for(int i=0;i<nums.size();i=i+2){ for(int j=nums[i];j>0;j--){ res.push_back(nums[i+1]);
2022-04-28 22:55:45
111
原创 呀呀呀呀呀
class Solution { public: int consecutiveNumbersSum(int n) { int ans=0; for(int k=1;n-(k-1)*k/2>0;k++){ if((n-(k-1)*k/2)%k==0)ans++; } return ans; } }; 题目 class Solution { public: int consecutiveNumb.
2022-04-28 16:41:13
131
原创 滑动窗口k
‘’’ class Solution { public: vector<vector> findContinuousSequence(int target) { int i = 1; // 滑动窗口的左边界 int j = 1; // 滑动窗口的右边界 int sum = 0; // 滑动窗口中数字的和 vector<vector> res; while (i <= target / 2) { if (sum < target) { // 右边界向
2022-04-28 12:06:08
119
原创 螺旋矩阵(规律)
本来想找一找牛逼的解,看了一堆,麻了,直接找规律!!! #include<bits/stdc++.h> using namespace std; int n,i,j; int dfs(int n,int i,int j){ if(i==1){ return j; } if(j==n){ return n+i-1; } if(i==n){ return 3*n-j-1; } if(j==1){
2022-04-22 23:15:23
558
原创 字符串KMP算法
题目 #include <iostream> #include <string> using namespace std; const int N = 100010, M = 1000010; int n, m; //int ne[N]; char s[M], p[N]; int * findNext(string p){ int j = 0; int k = -1; int m = p.length(); int * next = new int[m+10]; nex
2022-04-22 18:06:54
105
原创 中缀表达式的值
#include<iostream> #include<cstdio> #include<string> using namespace std; #include<stack> #include<queue> #include<map> struct node{ double num; char op; bool flag; }; string str; stack<node>s; queue<node>
2022-04-19 18:23:13
171
原创 getline(str,90)
#include #include #include using namespace std; int main (){ char str [90]; cin.getline(str,90); int len = strlen ( str ), r =0, h =0;// r 为行, h 为列 char ans [90][90];// ans [0]~ ans [ r ]存放单词 for ( int i =0; i < len ; i ++){ if ( str [ i ]!=’ ‘){ ans
2022-03-24 16:39:40
123
原创 不知道搞了个啥,笔记
import java.io.File; import java.io.FileFilter; import java.io.IOException; public class FileDemo { public static void printDir(File dir) { /* if(dir.isFile()){ System.out.println(dir); } else{ File[] files=dir.listFiles(); for(File file:files){ if(file.i
2021-11-26 00:10:53
189
原创 2021-11-15
integr的compareto实现 //compareTo public int compareTo(Integer anotherInteger) { return compare(this.value, anotherInteger.value); } //compare public static int compare(int x, int y) { return (x < y) ? -1 : ((x == y) ? 0 : 1); }
2021-11-15 15:53:35
255
原创 2021-11-05
C语言复习1 通过递归替代循环。 通过短路运算符来替代条件判断。 while(scanf("%d",&a))!=EOF)怎么结束? 由于是手动输入(从键盘输入)的数据信息,所以我们要给让此类循环结束,需要我们键入ctrl+z 再加enter就结束了 交换变量可用异或 ...
2021-11-05 00:19:32
106
原创 2021-02-05
第二个 #include using namespace std; #include struct hero { string sex; int age; string name; }; void bubblesort(struct hero herroarray[], int len) { for (int i = 0; i < len-1; i++) { for (int j = 0; j < len - 1 - i; j++) { if (herroarray[j].age>
2021-02-05 21:30:35
97
原创 2021-02-05
菜鸟学习C加加的第一天 用结构体表示,老师和学生的信息 #include using namespace std; #include #include struct student { string name; int score; }; struct teacher { string name; struct student sarray[5]; }; void allocatespace(struct teacher tarray[], int len) { string nameseed = “ABC
2021-02-05 20:51:05
145
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅