#1305

All Elements in Two Binary Search Trees

pupil · 435 · lc medium +25 · verified · 80.2% accepted · 3,187 likes · top 92%

Description

You have two binary search trees rooted at root1 and root2. Collect every integer from both trees and return them in a single list 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]

Code

1
2
3
4
5
6
7
8
9