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
阅读全文
摘要:``` class Solution { public: int singleNumber(vector& nums) { int res=0; for(auto i:nums) res^=i; return res; } }; ```
阅读全文
摘要:* 为什么这题我都不会,脑袋有点累,状态真差 ``` class Solution { public: int longestConsecutive(vector& nums) { unordered_set s(nums.begin(),nums.end());//记录数字是否出现过 int re
阅读全文
摘要:``` 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
阅读全文
摘要:``` 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
阅读全文
摘要:``` 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
阅读全文
摘要:``` class Solution { public: vector> ans; vector path; void dfs(vector nums,int idx)//选择path的下一个数填什么,从下标idx开始选 { if(path.size()>=2) ans.push_back(path
阅读全文
摘要:``` 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; }
阅读全文
摘要:``` class Solution { public: unordered_map cnt; vector> res; vector path; vector> subsetsWithDup(vector& nums) { for(auto i:nums) cnt[i]++; dfs(-10);/
阅读全文
摘要:``` class Solution { public: vector> res; vector> combinationSum2(vector& candidates, int target) { sort(candidates.begin(),candidates.end()); dfs(can
阅读全文
摘要:``` class Solution { public: vector> res; vector> combinationSum(vector& candidates, int target) { dfs(candidates,0,target); return res; } vector path
阅读全文
摘要:#### 思路 - 遍历所有节点,如果当前节点不在所给区间里,删除该点;否则 - 如果该点要被删除,将其左右子树其中之一提上来即可 - 根节点位于左右子树取值区间的中间,如果该点要被删除,那么一定存在不满足要求的子树,不可能两棵子树同时保留 #### 代码 ```c class Solution {
阅读全文
摘要:```c class Solution { public: TreeNode* deleteNode(TreeNode* root, int key) { del(root,key); return root; } void del(TreeNode* &root,int key) { if(!ro
阅读全文
摘要:```c class Solution { public: void dfs(TreeNode* root,int &sum)//从大到小遍历所有节点 { if(!root) return; dfs(root->right,sum); sum+=root->val; root->val=sum; d
阅读全文
摘要:``` class Solution { public: vector res; int cnt=0; int find(TreeNode* root,int val)//返回当前子树值为val的个数 { if(!root) return 0; return find(root->left,val)
阅读全文
摘要:```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
阅读全文
摘要:```c class Solution { public: TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { if(p->valval&&q->valval) return lowestCommonA
阅读全文