Description
Submission
/**
* 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 {
vector<int> rets;
void dfs(TreeNode* root) {
if(!root) return;
rets.push_back(root->val);
if(root->left) dfs(root->left);
if(root->right) dfs(root->right);
}
public:
vector<int> getAllElements(TreeNode* root1, TreeNode* root2) {
dfs(root1);
dfs(root2);
sort(rets.begin(), rets.end());
return rets;
}
};