随笔分类 -  leetcode

摘要:``` class Solution { public: vector productExceptSelf(vector& nums) { vector q; int t=1; for(auto i:nums) { q.push_back(t); t*=i; } t=1; for(int i=num 阅读全文
posted @ 2023-07-13 10:35 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: ListNode* reverse(ListNode* head)//翻转以head为头节点的链表 { if(!head||!head->next) return head; auto a=head,b=head->next; while(b 阅读全文
posted @ 2023-07-12 12:17 穿过雾的阴霾 阅读(3) 评论(0) 推荐(0) 编辑
摘要:# 小根堆 ``` class Solution { public: int findKthLargest(vector& nums, int k) { priority_queue,greater> q; for(auto x:nums) { if(q.size()& nums, int k) { 阅读全文
posted @ 2023-07-10 12:46 穿过雾的阴霾 阅读(3) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: bool canFinish(int n, vector>& pre) { if(pre.empty()||pre[0].empty()) return true; vector> g(n,vector(n,false)); for(auto 阅读全文
posted @ 2023-07-09 11:49 穿过雾的阴霾 阅读(3) 评论(0) 推荐(0) 编辑
摘要:``` /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x 阅读全文
posted @ 2023-07-08 14:48 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: bool st[310][310]; int dx[4]={0,0,-1,1},dy[4]={-1,1,0,0}; int m,n; int numIslands(vector>& g) { int res=0; n=g.size(),m=g 阅读全文
posted @ 2023-07-07 12:11 穿过雾的阴霾 阅读(3) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: int majorityElement(vector& nums) { int cnt=1; int res=nums[0]; for(int i=1;i<nums.size();i++) { if(nums[i]==res) cnt++; 阅读全文
posted @ 2023-07-07 11:54 穿过雾的阴霾 阅读(2) 评论(0) 推荐(0) 编辑
摘要:``` /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class 阅读全文
posted @ 2023-07-05 18:43 穿过雾的阴霾 阅读(6) 评论(0) 推荐(0) 编辑
摘要:#使用双栈 ``` class MinStack { public: stack st, min_st; MinStack() { min_st.push(INT_MAX); } void push(int val) { st.push(val); int min_val=min_st.top(); 阅读全文
posted @ 2023-07-05 10:39 穿过雾的阴霾 阅读(7) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: static const int N=20010; int f[N],g[N]; int maxProduct(vector& nums) { int n=nums.size(); int res=nums[0]; f[0]=g[0]=num 阅读全文
posted @ 2023-07-04 11:27 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: ListNode* sortList(ListNode* head) { if(!head||!head->next) return head; ListNode* fast=head,*slow=head; while(fast->next 阅读全文
posted @ 2023-07-04 00:24 穿过雾的阴霾 阅读(8) 评论(0) 推荐(0) 编辑
摘要:``` class LRUCache { public: struct node { int key,val; node *l,*r; node(int a,int b) { l=r=NULL; key=a; val=b; } }*L,*R; unordered_map mp;//保存key和节点的 阅读全文
posted @ 2023-07-03 15:26 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:``` /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class 阅读全文
posted @ 2023-07-01 10:30 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:#取巧 ``` class Solution { public: const int INF=1e9; bool hasCycle(ListNode *head) { bool res=false; auto p=head; while(p) { if(p->val==INF) { res=true 阅读全文
posted @ 2023-06-30 16:41 穿过雾的阴霾 阅读(6) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: int singleNumber(vector& nums) { int res=0; for(auto i:nums) res^=i; return res; } }; ``` 阅读全文
posted @ 2023-06-30 16:09 穿过雾的阴霾 阅读(3) 评论(0) 推荐(0) 编辑
摘要:* 为什么这题我都不会,脑袋有点累,状态真差 ``` class Solution { public: int longestConsecutive(vector& nums) { unordered_set s(nums.begin(),nums.end());//记录数字是否出现过 int re 阅读全文
posted @ 2023-06-26 15:05 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: vector row,anti_diag,col,diag; int res=0; void dfs(int n,int x,int y,int cnt) { if(y==n) y=0,x++; if(x==n) { if(cnt==n) r 阅读全文
posted @ 2023-06-13 10:11 穿过雾的阴霾 阅读(2) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: vector> res; vector path; vector anti_diag,col,diag; void dfs(int n,int u) { if(u==n) { res.push_back(path); return; } st 阅读全文
posted @ 2023-06-13 09:51 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: vector res; void dfs(string s,string path,int idx,int cnt)//枚举下一个逗号填哪 { if(idx>=s.size()) { if(idx==s.size()&&cnt==4) { p 阅读全文
posted @ 2023-06-12 10:26 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: vector> ans; vector path; void dfs(vector nums,int idx)//选择path的下一个数填什么,从下标idx开始选 { if(path.size()>=2) ans.push_back(path 阅读全文
posted @ 2023-06-11 11:28 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑

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