码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode872

时间:2018-09-27 22:19:40      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:type   oid   tor   tree   lse   color   similar   ==   treenode   

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 == 1)
            {
                v1.push_back(tree->val);
            }
            else
            {
                v2.push_back(tree->val);
            }
        }
    }
    bool leafSimilar(TreeNode* root1, TreeNode* root2) {
        GetLeaf(root1, 1);
        GetLeaf(root2, 2);
        if (v1.size() != v2.size())
        {
            return false;
        }
        for (int i = 0; i < v1.size(); i++)
        {
            if (v1[i] != v2[i])
            {
                return false;
            }
        }
        return true;
    }
};

 

leetcode872

标签:type   oid   tor   tree   lse   color   similar   ==   treenode   

原文地址:https://www.cnblogs.com/asenyang/p/9715495.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!