上一页 1 2 3 4 5 6 7 8 9 10 ··· 20 下一页
摘要: ```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)
摘要: # 思路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)
摘要: ``` 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)
摘要: ``` 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)
摘要: ``` 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)
摘要: ``` 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)
摘要: ``` 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)
摘要: ``` /** * 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)
摘要: ``` 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)
摘要: ``` 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 下一页