会员
周边
新闻
博问
闪存
众包
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
穿过雾的阴霾
博客园
首页
新随笔
联系
订阅
管理
上一页
1
2
3
4
5
6
7
8
9
···
20
下一页
2023年6月10日
LeetCode 47. 全排列 II
摘要: ``` 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)
2023年6月7日
LeetCode 90. 子集 II
摘要: ``` 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)
LeetCode 40. 组合总和 II
摘要: ``` 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)
LeetCode 39. 组合总和
摘要: ``` 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)
2023年6月5日
LeetCode 669. 修剪二叉搜索树
摘要: #### 思路 - 遍历所有节点,如果当前节点不在所给区间里,删除该点;否则 - 如果该点要被删除,将其左右子树其中之一提上来即可 - 根节点位于左右子树取值区间的中间,如果该点要被删除,那么一定存在不满足要求的子树,不可能两棵子树同时保留 #### 代码 ```c class Solution {
阅读全文
posted @ 2023-06-05 11:38 穿过雾的阴霾
阅读(14)
评论(0)
推荐(0)
2023年6月4日
LeetCode 450. 删除二叉搜索树中的节点
摘要: ```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)
LeetCode 538. 把二叉搜索树转换为累加树
摘要: ```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)
2023年6月3日
LeetCode 501. 二叉搜索树中的众数
摘要: ``` 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)
2023年6月2日
LeetCode 236_ 二叉树的最近公共祖先
摘要: ```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)
LeetCode235. 二叉搜索树的最近公共祖先
摘要: ```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
下一页
公告