Example Analysis of BST input as the Sum of two numbers in LeetCode Easy653
The input of the sum of two numbers in LeetCode Easy653 is the example analysis of BST. Aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Description
Https://leetcode.com/problems/two-sum-iv-input-is-a-bst/
Given the root of a Binary Search Tree and a target number k, return true if there exist two elements in the BST such that their sum is equal to the given target.
Example 1:
Input: root = [5, 9Output, 3, 6, 2, 4 and 7], k = 9Output: true
Example 2:
Input: root = [5, 28Output, 3, 6, 2, 4 and 7], k = 28Output: false
Example 3:
Input: root = [2je 1jue 3], k = 4Output: true
Example 4:
Input: root = [2je 1jue 3], k = 1Output: false
Example 5:
Input: root = [2 Output 1: true], k = 3
Constraints:
The number of nodes in the tree is in the range $[1,10 ^ 4] $.
$- 10 ^ 4