class Solution {
public:
vector<int>A;
void vis(TreeNode *t) {
if (t == NULL)return;
if (t->left == NULL&&t->right == NULL)A.push_back(t->val);
vis(t->left);
vis(t->right);
}
bool leafSimilar(TreeNode* root1, TreeNode* root2) {
vector<int>a1, a2;
A.clear();
vis(root1);
a1 = A;
A.clear();
vis(root2);
a2 = A;
if (a1 == a2)return true;
return false;
}
};
872. Leaf-Similar Trees
最新推荐文章于 2020-10-08 09:12:25 发布