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的更多相关文章

  1. [Swift]LeetCode872. 叶子相似的树 | Leaf-Similar Trees

    Consider all the leaves of a binary tree.  From left to right order, the values of those leaves form ...

  2. LeetCode872. Leaf-Similar Trees

    自己的代码: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = ...

  3. Leetcode872.Leaf-Similar Trees叶子相似的树

    请考虑一颗二叉树上所有的叶子,这些叶子的值按从左到右的顺序排列形成一个 叶值序列 . 举个例子,如上图所示,给定一颗叶值序列为 (6, 7, 4, 9, 8) 的树. 如果有两颗二叉树的叶值序列是相同 ...

  4. LeetCode872. 叶子相似的树

    题目 1 class Solution { 2 public: 3 vector<int>ans1; 4 vector<int>ans2; 5 bool leafSimilar ...

  5. LeetCode 872. 叶子相似的树(Leaf-Similar Trees)

    872. 叶子相似的树 872. Leaf-Similar Trees 题目描述 请考虑一颗二叉树上所有的叶子,这些叶子的值按从左到右的顺序排列形成一个叶值序列. LeetCode872. Leaf- ...

随机推荐

  1. 013对象—— __clone __toString __call

    <?php /** * */ //__clone()方法对一个对象实例进行的浅复制,对象内的基本数值类型进行的是传值复制 /*class a { public $uname; public $n ...

  2. C# List 排序

    (转自:http://www.cnblogs.com/bradwarden/archive/2012/06/19/2554854.html) 第一种:实体类实现IComparable接口,而且必须实现 ...

  3. switch遇到0的问题

    你是否经常有switch来代替if else?是否因为使用了switch,提高代码的执行效率而庆幸?好吧,你和我一样,但也许你没有遇到下面的问题. 这个小程序,会输出什么呢?会是'00'么?   结果 ...

  4. main(int argc, char *argv[])详解

    argc是命令行总的参数个数     argv[]是argc个参数,其中第0个参数是程序的全名,以后的参数     命令行后面跟的用户输入的参数,比如:     int   main(int   ar ...

  5. Solr初步使用

    参考此文:https://blog.csdn.net/frankcheng5143/article/details/71159936

  6. 【MFC】MFC中窗口重绘

    MFC中窗口重绘 摘自:http://blog.csdn.net/shuilan0066/article/details/5859057 在刷新窗口时经常要调用重绘函数 MFC提供了三个函数用于窗口重 ...

  7. SQL面试题-行列互换-if、【case when】

    http://www.cda.cn/view/21469.html tb_lemon_grade中,表中字段id,student_name,course,score分别表示成绩id,学生姓名,课程名称 ...

  8. PING分组网间探测 ICMP协议

      1.Ping的基础知识 Ping是潜水艇人员的专用术语,表示回应的声纳脉冲,在网络中Ping 是一个十分好用的TCP/IP工具.它主要的功能是用来检测网络的连通情况和分析网络速度.是ICMP的一个 ...

  9. Hive中使用Python实现Transform时遇到Broken pipe错误排查

    Hive中有一表,列分隔符为冒号(:),有一列utime是Timestamp格式,需要转成Weekday存到新表. 利用Python写一个Pipeline的Transform,weekday.py的代 ...

  10. 洛谷 P2909 [USACO08OPEN]牛的车Cow Cars

    传送门 题目大意: m个车道. 如果第i头牛前面有k头牛,那么这头牛的最大速度会 变为原本的速度-k*D,如果速度小于l这头牛就不能行驶. 题解:贪心 让初始速度小的牛在前面 代码: #include ...