652. Find Duplicate Subtrees
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
unordered_map<string, vector<TreeNode*>> s;
vector<TreeNode*> findDuplicateSubtrees(TreeNode* root) {
dfs(root);
vector<TreeNode*> res;
for (auto & i : s) {
if (i.second.size() > )
res.push_back(i.second[]);
}
return res;
}
string dfs(TreeNode* root) {
if (root == NULL) return "";
string t = "(" + dfs(root->left) + to_string(root->val) + dfs(root->right) + ")";
s[t].push_back(root);
return t;
}
};
652. Find Duplicate Subtrees的更多相关文章
- 【LeetCode】652. Find Duplicate Subtrees 解题报告(Python)
[LeetCode]652. Find Duplicate Subtrees 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
- 652. Find Duplicate Subtrees找出重复的子树
[抄题]: 就是出现了多次的子树,可以只包括一个点. Given a binary tree, return all duplicate subtrees. For each kind of dupl ...
- LC 652. Find Duplicate Subtrees
Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only ne ...
- [LeetCode]652. Find Duplicate Subtrees找到重复树
核心思想是:序列化树 序列化后,用String可以唯一的代表一棵树,其实就是前序遍历改造一下(空节点用符号表示): 一边序列化,一边用哈希表记录有没有重复的,如果有就添加,注意不能重复添加. 重点就是 ...
- LeetCode 652: 寻找重复的子树 Find Duplicate Subtrees
LeetCode 652: 寻找重复的子树 Find Duplicate Subtrees 题目: 给定一棵二叉树,返回所有重复的子树.对于同一类的重复子树,你只需要返回其中任意一棵的根结点即可. 两 ...
- [LeetCode] Find Duplicate Subtrees 寻找重复树
Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only ne ...
- [Swift]LeetCode652. 寻找重复的子树 | Find Duplicate Subtrees
Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only ne ...
- LeetCode - Find Duplicate Subtrees
Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only ne ...
- LeetCode——Find Duplicate Subtrees
Question Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, yo ...
随机推荐
- Jcrontab定时任务
两篇博客: http://blog.csdn.net/jijijiujiu123/article/details/9086847 网站同事写的(chenrui) ...
- 微软开源 PowerShell 并支持 Linux 和 OS X
微软近日宣布开源 PowerShell,开始支持 Linux 和 OSX.PowerShell 是面向 Windows 和 Windows Server 的自动化平台和可扩展脚本语言,可帮助用户简化系 ...
- Blob, Uint8Aray, atob/btoa in lt IE9 browser
Blob, Uint8Aray, atob/btoa in lt IE9 browser 标签(空格分隔): compatibility 之前写的代码全部在Chrome调试,用IE打开发现各种问题. ...
- 实验验证stack和heap中是否被设初值
#include <iostream> #include <stdlib.h> using namespace std; class Foo { public: int i; ...
- 科技巨头之微软-Microsoft
提起微软Microsoft,我想应该是无人不知无人不晓.Windows操作系统,Office办公软件,是我们日常经常用到的工具.而微软的创始人正是前世界首富比尔盖茨. 1997年,我刚上初中.当时学校 ...
- pip pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool
设置超时时间: pip --default-timeout=100 install Pillow
- OO思想举例,控制翻转,依赖注入
(转自kumaws,原帖地址:http://www.cnblogs.com/kumaws/archive/2009/04/06/from_interface_to_DependencyInjectio ...
- scrum3
首先我一直做的是框架的设计,但不同的是这次我们整合完善了这个软件目前的所有需求也定义好了它的大题框架,总的来说设计部分已经结束,现在也就是本次冲刺,我们将重点进行整个软件的数据库编程环节,也就是用SQ ...
- SQA计划和测试规程
一.SQA计划 (一)目的 本计划的目的是定义我们该小组所做的“云医院”项目的SQA任务和职责,在项目过程中应遵循的流程.规范和约定等,以确保软件质量得到维持. (二)范围 本计划应用于“云医院”项目 ...
- webstorm识别php代码
在 setting --editor--filetype---找到html 在下面的框里点右边加好,添加*.php