1305. All Elements in Two Binary Search Trees
Python
class Solution:
def getAllElements(self, root1: TreeNode, root2: TreeNode) -> List[int]:
tree1 = self._travel(root1, [])
tree2 = self._travel(root2, [])
return sorted(tree1 + tree2)
def _travel(self, node, result):
if not node:
return result
self._travel(node.left, result)
result.append(node.val)
self._travel(node.right, result)
return result