/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
void func(TreeNode* root, vector<int>& res){
if (root==NULL){
return;
}
func(root->left, res);
res.push_back(root->val);
func(root->right, res);
return;
}
vector<int> getAllElements(TreeNode* root1, TreeNode* root2) {
vector<int> res;
func(root1, res);
func(root2, res);
sort(res.begin(), res.end());
return res;
}
};
1305. All Elements in Two Binary Search Trees
最新推荐文章于 2024-09-28 10:34:40 发布