Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    653 - Two Sum IV - Input is a BST.

    Easy

    Given the root of a binary search tree and an integer k, return true if there exist two elements in the BST such that their sum is equal to k, or false otherwise.

    Example 1:

    Input: root = 5,3,6,2,4,null,7, k = 9

    Output: true

    Example 2:

    Input: root = 5,3,6,2,4,null,7, k = 28

    Output: false

    Constraints:

    • The number of nodes in the tree is in the range <code>1, 10<sup>4</sup></code>.

    • <code>-10<sup>4</sup><= Node.val <= 10<sup>4</sup></code>

    • root is guaranteed to be a valid binary search tree.

    • <code>-10<sup>5</sup><= k <= 10<sup>5</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Boolean findTarget(TreeNode root, Integer k)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait