/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root1
* @param {TreeNode} root2
* @return {number[]}
*/
var getAllElements = function(root1, root2) {
let arr_left = []
let arr_right = []
let dfs = (data, arr) => {
if (data) {
dfs(data.left, arr)
dfs(data.right, arr)
arr.push(data.val)
}
}
dfs(root1, arr_left)
dfs(root2, arr_right)
return arr_left.concat(arr_right).sort((a, b) => {return a - b})
};