java.lang.Object
g0601_0700.s0653_two_sum_iv_input_is_a_bst.Solution

public class Solution extends Object
653 - Two Sum IV - Input is a BST.<p>Easy</p> <p>Given the <code>root</code> of a Binary Search Tree and a target number <code>k</code>, return <em><code>true</code> if there exist two elements in the BST such that their sum is equal to the given target</em>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/09/21/sum_tree_1.jpg" alt="" /></p> <p><strong>Input:</strong> root = [5,3,6,2,4,null,7], k = 9</p> <p><strong>Output:</strong> true</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/09/21/sum_tree_2.jpg" alt="" /></p> <p><strong>Input:</strong> root = [5,3,6,2,4,null,7], k = 28</p> <p><strong>Output:</strong> false</p> <p><strong>Constraints:</strong></p> <ul> <li>The number of nodes in the tree is in the range <code>[1, 10<sup>4</sup>]</code>.</li> <li><code>-10<sup>4</sup> <= Node.val <= 10<sup>4</sup></code></li> <li><code>root</code> is guaranteed to be a <strong>valid</strong> binary search tree.</li> <li><code>-10<sup>5</sup> <= k <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • findTarget

      public boolean findTarget(TreeNode root, int k)