Watch 10 video solutions for All Elements in Two Binary Search Trees, a medium level problem involving Tree, Depth-First Search, Binary Search Tree. This walkthrough by Knowledge Center has 5,001 views views. Want to try solving it yourself? Practice on FleetCode or read the detailed text solution.
Given two binary search trees root1 and root2, return a list containing all the integers from both trees sorted in ascending order.
Example 1:
Input: root1 = [2,1,4], root2 = [1,0,3] Output: [0,1,1,2,3,4]
Example 2:
Input: root1 = [1,null,8], root2 = [8,1] Output: [1,1,8,8]
Constraints:
[0, 5000].-105 <= Node.val <= 105