Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of BST input as the Sum of two numbers in LeetCode Easy653

Shulou Source: shulou.com Published: 2022-06-03 11:53:46 09月15日 Update

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

Tags: Analysis pointers sum of questions examples inputs methods more help answers easy necessary easy content guys partners features knowledge articles nodes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information OPPO Reno Shulou Technology Linux Redmi