会员
周边
新闻
博问
闪存
众包
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
穿过雾的阴霾
博客园
首页
新随笔
联系
订阅
管理
上一页
1
2
3
4
5
6
7
8
9
10
···
20
下一页
2023年5月28日
LeetCode 652. 寻找重复的子树
摘要: ```c class Solution { public: vector res; unordered_map hashmap;//记录每一个子树出现的次数 string dfs(TreeNode* root) { if(!root) return ""; string str=""; str+=t
阅读全文
posted @ 2023-05-28 14:47 穿过雾的阴霾
阅读(18)
评论(0)
推荐(0)
2023年5月27日
LeetCode 114. 二叉树展开为链表
摘要: # 思路1 ``` class Solution { public: void flatten(TreeNode* root) { while(root) { auto p=root->left; if(p)//找到左儿子的右链 { while(p->right) p=p->right; //将右链
阅读全文
posted @ 2023-05-27 10:30 穿过雾的阴霾
阅读(9)
评论(0)
推荐(0)
2023年5月24日
LeetCode 98. 验证二叉搜索树
摘要: ``` class Solution { public: vector dfs(TreeNode* root)//依次返回是否是二叉搜索树,最大值最小值 { vector res{1,root->val,root->val}; if(root->left) { auto l=dfs(root->le
阅读全文
posted @ 2023-05-24 14:39 穿过雾的阴霾
阅读(15)
评论(0)
推荐(0)
LeetCode 222. 完全二叉树的节点个数
摘要: ``` class Solution { public: int countNodes(TreeNode* root) { if(!root) return 0; auto l=root->left,r=root->right; int x=1,y=1;//记录左右两边层数 while(l) l=l
阅读全文
posted @ 2023-05-24 14:15 穿过雾的阴霾
阅读(17)
评论(0)
推荐(0)
2023年5月23日
LeetCode 95. 不同的二叉搜索树 II
摘要: ``` class Solution { public: vector dfs(int l,int r)//返回以n为根节点的所有可能子树 { vector res; if(l>r) return {NULL}; for(int k=l;k left=dfs(l,k-1); vector right
阅读全文
posted @ 2023-05-23 10:50 穿过雾的阴霾
阅读(15)
评论(0)
推荐(0)
2023年5月22日
LeetCode 103. 二叉树的锯齿形层次遍历
摘要: ``` class Solution { public: vector> res; void bfs(TreeNode* root) { queue q; q.push(root); int cnt=0; while(!q.empty()) { vector level; int len=q.siz
阅读全文
posted @ 2023-05-22 13:24 穿过雾的阴霾
阅读(13)
评论(0)
推荐(0)
102. 二叉树的层序遍历
摘要: ``` class Solution { public: vector> res; void bfs(TreeNode* root) { queue q; q.push(root); int last=0; while(!q.empty()) { vector level; int len=q.si
阅读全文
posted @ 2023-05-22 13:15 穿过雾的阴霾
阅读(15)
评论(0)
推荐(0)
2023年5月21日
145. 二叉树的后序遍历
摘要: ``` /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr),
阅读全文
posted @ 2023-05-21 15:23 穿过雾的阴霾
阅读(19)
评论(0)
推荐(0)
94. 二叉树的中序遍历
摘要: ``` class Solution { public: vector inorderTraversal(TreeNode* root) { vector res; stack st; while(root||st.size()) { while(root) { st.push(root); roo
阅读全文
posted @ 2023-05-21 15:05 穿过雾的阴霾
阅读(18)
评论(0)
推荐(0)
2023年5月20日
构建乘积数组
摘要: ``` class Solution { public: vector multiply(const vector& nums) { int n=nums.size(); if(n==0) return vector(); vector q(n,1); for (int i = 1,t=nums[0
阅读全文
posted @ 2023-05-20 15:48 穿过雾的阴霾
阅读(18)
评论(0)
推荐(0)
上一页
1
2
3
4
5
6
7
8
9
10
···
20
下一页
公告