- 博客(16)
- 收藏
- 关注
原创 做大小根堆相关用到的东西
#include <iostream>#include <algorithm>//sort#include <vector>#include <functional>//greater和less#include <queue>//priority_queuepriority_queue<int,vector<int>,greater<int>> q;//从小到大q.pop();//弹出最小的那个(队
2022-03-20 16:18:30 251
原创 c++primer第十五章:面向对象程序设计(更新中)
某个类的友元可以访问该类的所有成员可以通过该类的对象访问该类基类的protected成员不可以直接访问该类的基类的成员(包括基类的protected成员)不可以访问该类的派生类的成员某个类的private成员只能被该类的成员或该类的友元访问某个类的protected成员可以被其派生类的成员函数通过该派生类的对象访问可以被其派生类的友元通过该派生类的对象访问可以被该类的成员或友元访问某个类的public成员可以被类的所有用户访问派生访问说明符(public priva
2022-03-19 17:06:18 634
原创 Leetcode学习8
反转链表206 反转链表/** * 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(
2022-03-07 17:28:41 441
原创 Leetcode学习6
20 有效的括号class Solution {public: bool isValid(string s) { stack<char> stk; int n=s.size(); for(int i=0;i<n;i++) { if(s[i]=='{'||s[i]=='['||s[i]=='(') { stk.emplace(s[i]);
2022-03-06 16:59:10 90
原创 Leetcode学习5
15.三数之和class Solution {public: vector<vector<int>> threeSum(vector<int>& nums) { vector<vector<int>> res={}; if (nums.size() < 3) { return res; } sort(nums.begin
2022-03-05 15:08:59 186
原创 Leetcoode学习4
5.最长回文子串(1) 暴力解法(超时)class Solution {public: bool check(string s) { int i=0,j=s.size()-1; while(i<s.size()/2) { if(s[i]!=s[j]) { return false; } i++;
2022-03-02 23:29:33 307
原创 Leetcode学习3
3.无重复字符的最长字串class Solution {public: int lengthOfLongestSubstring(string s) { unordered_map<char,int> note; int i=0,j=0,max=0; while(i<s.size()&&j<s.size()) { if(note.count(s[j])>0) //
2022-01-31 02:06:02 2798
原创 Leetcode学习2
2.两数相加自己写的堆溢出了。。。接下来就 看 答 案/** * 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, ListNo
2022-01-31 01:06:54 836
原创 Leetcode学习1
1.两数之和第一想法:排序后,设置头尾俩指针。指针所指两数之和大于target时,尾指针前移;指针所指两数之和小于target时,头指针后移。然而题目要求返回原先的顺序,故不可。//错误代码class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> copy=nums; sort(nums.begin(
2022-01-29 20:28:53 690
原创 Unity 单例
记录找了一天的bug:The object of type ‘GameObject’ has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.unity 切换场景的时候总是报错,说是某个类在尝试调用已经销毁的某个东西。错误原因:在设置这个类单例的时候顺手加了个DontDestroy
2021-07-08 21:18:23 208 1
原创 算法实践学习笔记3(dp)
目录矩阵连乘合并沙堆问题基础代码矩阵连乘合并沙堆问题#include <iostream>const int Max = 310;int a[Max] = {};//存沙子重量int m[Max][Max] = { 0 };//记录最小代价int p[Max][Max] = { 0 };//p[i][j]为a[i]到a[j]的和int Minimum_cost(int n){ for (int i = 1; i <= n; i++) { m[i][i] = 0
2020-10-18 14:52:54 149
原创 算法实践学习笔记2
学习day2可能含有重复字符的序列全排列问题重点:在不含重复字符的全排列的基础上想办法使得在树的同一层不会添加相同的元素解决方法:在找全排列序列之前将原序列按字典的顺序进行排序,然后再找全排列序列。注意:每一层构造完之后要重新排序恢复原样每一层剩余的可选元素也要先排序后排列#include <iostream>char list[11] = {};int cnt(char s[]){ int count = 0; char x; while (1)
2020-10-12 23:41:13 63
原创 算法实践学习笔记1
学习day1double pow(double,double)longlong与double转换 longlong存不了浮点数的值数组尽量不要在函数里开 易爆栈遇到取模的题 每一步运算都要取模记忆化搜索设初值为0来判断要注意 可能结果是0using namespace容易产生命名冲突x>>=1 x右移一位 相当于除以2 但更快判断语句m?x:y中x和y都必须是值或表达式,如果不满足if不作动作,则随意填一个值即可void do1(){};void do2(){};if
2020-10-11 23:07:47 58
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人