leetcode872
class Solution {
public:
vector<int> v1;
vector<int> v2;
void GetLeaf(TreeNode* tree, int type)
{
if (tree->left != NULL || tree->right != NULL)
{
if (tree->left != NULL)
{
GetLeaf(tree->left, type);
}
if (tree->right != NULL)
{
GetLeaf(tree->right, type);
}
}
else
{
if (type == )
{
v1.push_back(tree->val);
}
else
{
v2.push_back(tree->val);
}
}
}
bool leafSimilar(TreeNode* root1, TreeNode* root2) {
GetLeaf(root1, );
GetLeaf(root2, );
if (v1.size() != v2.size())
{
return false;
}
for (int i = ; i < v1.size(); i++)
{
if (v1[i] != v2[i])
{
return false;
}
}
return true;
}
};
leetcode872的更多相关文章
- [Swift]LeetCode872. 叶子相似的树 | Leaf-Similar Trees
Consider all the leaves of a binary tree. From left to right order, the values of those leaves form ...
- LeetCode872. Leaf-Similar Trees
自己的代码: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = ...
- Leetcode872.Leaf-Similar Trees叶子相似的树
请考虑一颗二叉树上所有的叶子,这些叶子的值按从左到右的顺序排列形成一个 叶值序列 . 举个例子,如上图所示,给定一颗叶值序列为 (6, 7, 4, 9, 8) 的树. 如果有两颗二叉树的叶值序列是相同 ...
- LeetCode872. 叶子相似的树
题目 1 class Solution { 2 public: 3 vector<int>ans1; 4 vector<int>ans2; 5 bool leafSimilar ...
- LeetCode 872. 叶子相似的树(Leaf-Similar Trees)
872. 叶子相似的树 872. Leaf-Similar Trees 题目描述 请考虑一颗二叉树上所有的叶子,这些叶子的值按从左到右的顺序排列形成一个叶值序列. LeetCode872. Leaf- ...
随机推荐
- 内存保护机制及绕过方案——通过覆盖SEH异常处理函数绕过/GS机制
通过SEH链绕过GS保护机制 ⑴. 原理分析: i.异常处理结构(SEH)处理流程如下: SEH是基于线程的,每一个线程都有一个独立的SEH处理结果,在线程信息块中的第一个结构指向线程的异常列表,F ...
- Lua基础---运算符
众所周知,C,C++,python等语言都有运算符,那么Lua也不例外,因为它是C写的嘛! Lua分为主要三类运算符,分别是算术运算符,关系运算符,逻辑运算符,还有特殊运算符. 1.算术运算符有: + ...
- CentOS 7下sqlite3的问题修复
Centos7下的nltk启动问题 CentOS 7, Python 3.6,ipython 6.0.0 问题描述 ipython 启动ipython命令 import nltk 爆出以下的错误信息: ...
- Leetcode 1006. Clumsy Factorial
class Solution(object): def clumsy(self, N): """ :type N: int :rtype: int "" ...
- Java8新特性Optional、接口中的默认方法与静态方法
Optional Optional 类(java.util.Optional) 是一个容器类,代表一个值存在或不存在,原来用 null 表示一个值不存在,现在 Optional 可以更好的表达这个概念 ...
- ORM版,学生管理系统03
关于老师信息管理 建立多对多关系 第一种(通过外键建立) 自己写类,自己使其建立关系 缺点: 不能用Django ORM 多对多操作的语法 class Teacher(models.Model): t ...
- 细说 const
1.const 简单应用 const int pp=0 //pp 为整形常量,不能修改 还有另外一种不常用的方式 但是最容易误导 int const pp=0 //pp 为整形常量,不能修改 记住这两 ...
- python库之threading
This module constructs higher-level threading interfaces on top of the lower level python库之_threadmo ...
- 【WCF安全】使用X509证书自定义验证
接触WCF时间比较短,在项目中要使用X509证书,纠结好几天终于有了结论,因此为了方便日后查阅和园友交流特意单独将部分代码提出,并做以记录. 1.准备工作 制作X509证书,此处用到三个证书名称 导入 ...
- WCF服务引用时错误: 无法导入 wsdl:portType详细信息
WCF服务发布到IIS后,在客户端或WCFTestClient添加引用的时候报错如下: 错误: 无法导入 wsdl:portType详细信息: 在运行 WSDL 导入扩展时引发异常: System.S ...