# 1214. Two Sum BSTs

<https://leetcode.com/problems/two-sum-bsts>

## Description

Given the roots of two binary search trees, `root1` and `root2`, return `true` if and only if there is a node in the first tree and a node in the second tree whose values sum up to a given integer `target`.

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/02/10/ex1.png)

```
**Input:** root1 = [2,1,4], root2 = [1,0,3], target = 5
**Output:** true
**Explanation:** 2 and 3 sum up to 5.
```

**Example 2:**

![](https://assets.leetcode.com/uploads/2021/02/10/ex2.png)

```
**Input:** root1 = [0,-10,10], root2 = [5,1,7,0,2], target = 18
**Output:** false
```

**Constraints:**

* The number of nodes in each tree is in the range `[1, 5000]`.
* `-109 <= Node.val, target <= 109`

## ac

```java
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jaywin.gitbook.io/leetcode/solutions/1214-two-sum-bsts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
