标签: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; } };
标签:type oid tor tree lse color similar == treenode
原文地址:https://www.cnblogs.com/asenyang/p/9715495.html