07 2023 档案

摘要:``` class Solution { public: int hammingDistance(int x, int y) { int cnt=0; int t=x^y; while(t) { cnt+=(t&1); t>>=1; } return cnt; } }; ``` 阅读全文
posted @ 2023-07-30 22:29 穿过雾的阴霾 阅读(5) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: vector findDisappearedNumbers(vector& nums) { vector res; int n=nums.size(),offset=n+1; for(auto &num:nums) { int x=(num) 阅读全文
posted @ 2023-07-29 13:54 穿过雾的阴霾 阅读(9) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: vector findAnagrams(string s, string p) { unordered_map window,hash; vector res; for(auto i:p) hash[i]++; for(int i=0,j=0 阅读全文
posted @ 2023-07-28 12:30 穿过雾的阴霾 阅读(5) 评论(0) 推荐(1) 编辑
摘要:``` class Solution { public: int subarraySum(vector& nums, int k) { int n=nums.size(),res=0; vector s(n+1,0); unordered_map hash;//记录端点i之前所有前缀和的出现情况 f 阅读全文
posted @ 2023-07-26 12:26 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:``` /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), 阅读全文
posted @ 2023-07-26 11:56 穿过雾的阴霾 阅读(6) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: struct node { int val; int pre; node* next; node(int a,int b,node* c) { val=a; pre=b; next=c; } }; void insert(node* &hea 阅读全文
posted @ 2023-07-25 11:24 穿过雾的阴霾 阅读(7) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: vector calcEquation(vector>& equations, vector& values, vector>& queries) { unordered_set node;//记录所有节点 unordered_map> g; 阅读全文
posted @ 2023-07-24 12:25 穿过雾的阴霾 阅读(6) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: string dfs(string s,int &idx) { string str; while(idx'0'&&s[idx]='0'&&s[idx]<='9') num+=s[idx++]; if(s[idx]=='[') { int c 阅读全文
posted @ 2023-07-22 19:52 穿过雾的阴霾 阅读(3) 评论(0) 推荐(0) 编辑
摘要:# 快排思想 - 注意,这里是倒序排序,因此应该`while(nums[i].cnt>x);` ``` class Solution { public: struct element { int val,cnt; element(int a,int b) { val=a; cnt=b; } }; v 阅读全文
posted @ 2023-07-21 12:14 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: vector countBits(int n) { vector f(n+1); for(int i=1;i>1]+(i&1); return f; } }; ``` 阅读全文
posted @ 2023-07-20 23:13 穿过雾的阴霾 阅读(2) 评论(0) 推荐(0) 编辑
摘要:## 思路 本题有两点需要解决,如果确定括号的最少删除数量以及删除哪些括号 #### 求出最少删除数量 思路见 LeetCode 22. 括号生成 #### 已知删除数量,删除哪些括号? 直接爆搜,枚举每个括号是否删除 - 如果当前是左括号,枚举是否删除 (删除 0 还是 1 个) - 如果当前是左 阅读全文
posted @ 2023-07-18 13:04 穿过雾的阴霾 阅读(52) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: int findDuplicate(vector& nums) { if(nums.size()<2) return nums[0]; int n=nums.size(); int fast=0,slow=0; do { slow=nums[ 阅读全文
posted @ 2023-07-17 11:11 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: void moveZeroes(vector& nums) { if(nums.empty()) return; int n=nums.size(); int idx=n-1; while(idx>=0&&nums[idx]==0) idx- 阅读全文
posted @ 2023-07-15 09:30 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: bool searchMatrix(vector>& matrix, int target) { if(matrix.empty()||matrix[0].empty()) return false; int n=matrix.size(), 阅读全文
posted @ 2023-07-15 09:15 穿过雾的阴霾 阅读(3) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: vector maxSlidingWindow(vector& nums, int k) { deque q; vector res; for(int i=0;i=k) q.pop_front(); //插入新元素 while(q.size( 阅读全文
posted @ 2023-07-14 12:53 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:``` 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 穿过雾的阴霾 阅读(2) 评论(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 穿过雾的阴霾 阅读(3) 评论(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 穿过雾的阴霾 阅读(2) 评论(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 穿过雾的阴霾 阅读(5) 评论(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 穿过雾的阴霾 阅读(3) 评论(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 穿过雾的阴霾 阅读(7) 评论(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 穿过雾的阴霾 阅读(3) 评论(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) 编辑

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