653. Two Sum IV - Input is a BST Easy
#Hash Table#Two Pointers#Tree#Depth-First Search#Breadth-First Search#Binary Search Tree#Binary Tree
1/**
2 * [653] Two Sum IV - Input is a BST
3 *
4 * 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.
5 *
6 * Example 1:
7 * <img alt="" src="https://assets.leetcode.com/uploads/2020/09/21/sum_tree_1.jpg" style="width: 400px; height: 229px;" />
8 * Input: root = [5,3,6,2,4,null,7], k = 9
9 * Output: true
10 *
11 * Example 2:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2020/09/21/sum_tree_2.jpg" style="width: 400px; height: 229px;" />
13 * Input: root = [5,3,6,2,4,null,7], k = 28
14 * Output: false
15 *
16 *
17 * Constraints:
18 *
19 * The number of nodes in the tree is in the range [1, 10^4].
20 * -10^4 <= Node.val <= 10^4
21 * root is guaranteed to be a valid binary search tree.
22 * -10^5 <= k <= 10^5
23 *
24 */
25pub struct Solution {}
26use crate::util::tree::{TreeNode, to_tree};
27
28// problem: https://leetcode.com/problems/two-sum-iv-input-is-a-bst/
29// discuss: https://leetcode.com/problems/two-sum-iv-input-is-a-bst/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33// Definition for a binary tree node.
34// #[derive(Debug, PartialEq, Eq)]
35// pub struct TreeNode {
36// pub val: i32,
37// pub left: Option<Rc<RefCell<TreeNode>>>,
38// pub right: Option<Rc<RefCell<TreeNode>>>,
39// }
40//
41// impl TreeNode {
42// #[inline]
43// pub fn new(val: i32) -> Self {
44// TreeNode {
45// val,
46// left: None,
47// right: None
48// }
49// }
50// }
51use std::rc::Rc;
52use std::cell::RefCell;
53impl Solution {
54 pub fn find_target(root: Option<Rc<RefCell<TreeNode>>>, k: i32) -> bool {
55 false
56 }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_653() {
67 }
68}
69
Back
© 2025 bowen.ge All Rights Reserved.