上一页 1 2 3 4 5 6 7 8 9 ··· 20 下一页
摘要: ``` 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 穿过雾的阴霾 阅读(16) 评论(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 穿过雾的阴霾 阅读(11) 评论(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 穿过雾的阴霾 阅读(16) 评论(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 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0)
摘要: #### 思路 - 遍历所有节点,如果当前节点不在所给区间里,删除该点;否则 - 如果该点要被删除,将其左右子树其中之一提上来即可 - 根节点位于左右子树取值区间的中间,如果该点要被删除,那么一定存在不满足要求的子树,不可能两棵子树同时保留 #### 代码 ```c class Solution { 阅读全文
posted @ 2023-06-05 11:38 穿过雾的阴霾 阅读(14) 评论(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 穿过雾的阴霾 阅读(15) 评论(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 穿过雾的阴霾 阅读(11) 评论(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 穿过雾的阴霾 阅读(13) 评论(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 穿过雾的阴霾 阅读(12) 评论(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 穿过雾的阴霾 阅读(14) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 9 ··· 20 下一页