<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/18/q2-e1.png" style="width: 457px; height: 207px;" />
<pre>
<strong>Input:</strong> root1 = [2,1,4], root2 = [1,0,3]
<strong>Output:</strong> [0,1,1,2,3,4]
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/18/q2-e5-.png" style="width: 352px; height: 197px;" />
<pre>
<strong>Input:</strong> root1 = [1,null,8], root2 = [8,1]
<strong>Output:</strong> [1,1,8,8]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li>The number of nodes in each tree is in the range <code>[0, 5000]</code>.</li>
	<li><code>-10<sup>5</sup> &lt;= Node.val &lt;= 10<sup>5</sup></code></li>
</ul>

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def dfs(self, root, answer):
        if not root:
            return
        self.dfs(root.left, answer)
        answer.append(root.val)
        self.dfs(root.right, answer)
    
    def getAllElements(self, root1: TreeNode, root2: TreeNode) -> List[int]:
        left_answer = []
        self.dfs(root1, left_answer)
        
        right_answer = []
        self.dfs(root2, right_answer)
        
        answer = []
        left = 0
        right = 0
        
        while left < len(left_answer) and right < len(right_answer):
            left_value = left_answer[left]
            right_value = right_answer[right]
            if left_value <= right_value:
                answer.append(left_value)
                left += 1
            if right_value <= left_value:
                answer.append(right_value)
                right += 1
        
        while left < len(left_answer):
            left_value = left_answer[left]
            answer.append(left_value)
            left += 1
            
        while right < len(right_answer):
            right_value = right_answer[right]
            answer.append(right_value)
            right += 1
        
        return answer
20200