06 2023 档案

摘要:#取巧 ``` 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 穿过雾的阴霾 阅读(3) 评论(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) 编辑
摘要:``` class Solution { public: vector> res; vector path; bool st[10]; void dfs(vector nums,int u) { if(u==nums.size()) { res.push_back(path); return; } 阅读全文
posted @ 2023-06-10 19:57 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: unordered_map cnt; vector> res; vector path; vector> subsetsWithDup(vector& nums) { for(auto i:nums) cnt[i]++; dfs(-10);/ 阅读全文
posted @ 2023-06-07 21:04 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: vector> res; vector> combinationSum2(vector& candidates, int target) { sort(candidates.begin(),candidates.end()); dfs(can 阅读全文
posted @ 2023-06-07 20:37 穿过雾的阴霾 阅读(3) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: vector> res; vector> combinationSum(vector& candidates, int target) { dfs(candidates,0,target); return res; } vector path 阅读全文
posted @ 2023-06-07 20:09 穿过雾的阴霾 阅读(6) 评论(0) 推荐(0) 编辑
摘要:#### 思路 - 遍历所有节点,如果当前节点不在所给区间里,删除该点;否则 - 如果该点要被删除,将其左右子树其中之一提上来即可 - 根节点位于左右子树取值区间的中间,如果该点要被删除,那么一定存在不满足要求的子树,不可能两棵子树同时保留 #### 代码 ```c class Solution { 阅读全文
posted @ 2023-06-05 11:38 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:```c class Solution { public: TreeNode* deleteNode(TreeNode* root, int key) { del(root,key); return root; } void del(TreeNode* &root,int key) { if(!ro 阅读全文
posted @ 2023-06-04 15:13 穿过雾的阴霾 阅读(2) 评论(0) 推荐(0) 编辑
摘要:```c class Solution { public: void dfs(TreeNode* root,int &sum)//从大到小遍历所有节点 { if(!root) return; dfs(root->right,sum); sum+=root->val; root->val=sum; d 阅读全文
posted @ 2023-06-04 14:16 穿过雾的阴霾 阅读(3) 评论(0) 推荐(0) 编辑
摘要:``` class Solution { public: vector res; int cnt=0; int find(TreeNode* root,int val)//返回当前子树值为val的个数 { if(!root) return 0; return find(root->left,val) 阅读全文
posted @ 2023-06-03 20:30 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:```c class Solution { public: vector path1,path2; bool dfs(TreeNode* root,TreeNode* p,vector& path) { if(!root) return false; if(root==p||dfs(root->le 阅读全文
posted @ 2023-06-02 14:39 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:```c class Solution { public: TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { if(p->valval&&q->valval) return lowestCommonA 阅读全文
posted @ 2023-06-02 12:40 穿过雾的阴霾 阅读(2) 评论(0) 推荐(0) 编辑

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