We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */ class Solution { public: bool leafSimilar(TreeNode* root1, TreeNode* root2) { vector<int> root1Leaf; vector<int> root2Leaf; returnLeaf(root1, root1Leaf); returnLeaf(root2, root2Leaf); return root1Leaf == root2Leaf; } private: void returnLeaf(TreeNode* node, vector<int>& v) { if (node == nullptr) { return; } if (node->left == nullptr && node->right == nullptr) { v.push_back(node->val); } returnLeaf(node->left, v); returnLeaf(node->right, v); return; } };
==
The text was updated successfully, but these errors were encountered:
fkdl0048
No branches or pull requests
==
연산에 대해 좀 더 깊게 알게 됨.. 반복으로 비교할 필요가 없음The text was updated successfully, but these errors were encountered: