随笔分类 -  LeetCode

摘要:双指针法,结果只能从最左边或者最右边或者最左边加上最右边中取 class Solution { public: int findLengthOfShortestSubarray(vector<int>& arr) { int n = arr.size(),res = 1,res2 = 1,res3 阅读全文
posted @ 2023-03-26 07:52 智人心 阅读(17) 评论(0) 推荐(0) 编辑
摘要:静态链表 class Solution { public: int countStudents(vector<int>& students, vector<int>& sandwiches) { int stup = 0,sanp = 0,tmp; int n = students.size(),c 阅读全文
posted @ 2023-03-21 14:51 智人心 阅读(9) 评论(0) 推荐(0) 编辑
摘要:mysql的大小写转换,字符串连接函数 upper,lower,concat 阅读全文
posted @ 2023-03-21 07:53 智人心 阅读(10) 评论(0) 推荐(0) 编辑
摘要:注意map的按键和按值排序,按值排序需要转为vector #include<iostream> #include<map> #include<vector> #include<algorithm> using namespace std; int cmp(const pair<int,int>c1, 阅读全文
posted @ 2023-03-20 20:07 智人心 阅读(12) 评论(0) 推荐(0) 编辑
摘要:注意整行输入的格式 #include<iostream> #include<sstream> using namespace std; string reorderSpaces(string text) { string words[55]; int n = text.size(),cntWords 阅读全文
posted @ 2023-03-20 19:04 智人心 阅读(12) 评论(0) 推荐(0) 编辑
摘要:记得用sum,否则多条数据会冲突 # Write your MySQL query statement below select id, sum(case when month='Jan' then revenue else null end) Jan_Revenue, sum(case when 阅读全文
posted @ 2023-03-20 17:17 智人心 阅读(17) 评论(0) 推荐(0) 编辑
摘要:leetcode1544 字符串删除操作: string s = ”12345“; s.erase(m,n); 删除s中从m下标开始的n个字符 leetode1560 int data[n]; //分配栈内存 int*data = new int[n]; //分配堆内存并用栈内存data指向该内存区 阅读全文
posted @ 2022-07-21 16:48 智人心 阅读(15) 评论(0) 推荐(0) 编辑
摘要:unordered_map的遍历: 参见https://blog.csdn.net/qq_21539375/article/details/122003559 推荐: for(auto kv:map){ cout<<kv.first<<kv.second<<endl; } 阅读全文
posted @ 2022-06-15 22:23 智人心 阅读(13) 评论(0) 推荐(0) 编辑
摘要:线程通信 #include <semaphore.h> class Foo { protected: sem_t firstJobDone; sem_t secondJobDone; public: Foo() { sem_init(&firstJobDone, 0, 0); sem_init(&s 阅读全文
posted @ 2022-06-07 10:32 智人心 阅读(33) 评论(0) 推荐(0) 编辑
摘要:vector的插入: vector<int>v; v.insert(v.begin(),val); 阅读全文
posted @ 2022-06-07 10:14 智人心 阅读(16) 评论(0) 推荐(0) 编辑
摘要:用子字符串是过不了的,超时,需要一个一个字符判断 class Solution { public: string removeDuplicates(string s) { int n = s.size(),top = 0; if(n==1)return s; for(int i=0;i<n;i++) 阅读全文
posted @ 2022-06-07 09:20 智人心 阅读(18) 评论(0) 推荐(0) 编辑
摘要:参考https://blog.csdn.net/qq_33726635/article/details/106649623 C++的substr第二个参数表示长度 java的substr的第二个参数表示end下标 阅读全文
posted @ 2022-06-04 18:41 智人心 阅读(15) 评论(0) 推荐(0) 编辑
摘要:用优先队列存储前k大元素,堆顶是第k大元素,每一次添加一个元素道优先队列,如果队列长度大于k就pop堆顶元素 参考https://blog.csdn.net/qq_41687938/article/details/117827166 class KthLargest { public: priori 阅读全文
posted @ 2022-06-03 20:11 智人心 阅读(16) 评论(0) 推荐(0) 编辑
摘要:计算两个日期的间隔是否是一天 datediff(w1.recordDate,w2.recordDate)=1 {"headers": ["id"], "values": [[678], [446], [517], [955], [1007], [329], [603], [798], [812], 阅读全文
posted @ 2022-05-22 18:24 智人心 阅读(22) 评论(0) 推荐(0) 编辑
摘要:count自增的方法: let count = $count+1 阅读全文
posted @ 2022-05-22 17:39 智人心 阅读(14) 评论(0) 推荐(0) 编辑
摘要:队列的最后进入的元素q.back() /* // Definition for a Node. class Node { public: int val; vector<Node*> children; Node() {} Node(int _val) { val = _val; } Node(in 阅读全文
posted @ 2022-05-21 14:57 智人心 阅读(19) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int findLUSlength(string a, string b) { if(a==b)return -1; return max(a.size(),b.size()); } }; 有点无语 阅读全文
posted @ 2022-05-21 10:36 智人心 阅读(12) 评论(0) 推荐(0) 编辑
摘要:令队列一为主队列,队列二为辅助队列 当队列一空的时候,输入的元素直接放进来,即队头和队尾都是这个元素 当队列非空的时候,输入一个元素: 先把队列一的元素都放入队列二,输入此元素,再把队列二倒入队列一,这样就实现了新入队的元素在队列一的头,即后进先出 另外,queue<int>q的基本操作是: q.f 阅读全文
posted @ 2022-05-20 19:11 智人心 阅读(10) 评论(0) 推荐(0) 编辑
摘要:思路:分而治之 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullp 阅读全文
posted @ 2022-05-20 18:04 智人心 阅读(15) 评论(0) 推荐(0) 编辑
摘要:思路:由题意,若操作中有1出现返回true,若105次无1出现,返回false,至于105可以理解为取遍100以内的数的循环次数 阅读全文
posted @ 2022-05-20 17:49 智人心 阅读(16) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示