2236. Root Equals Sum of Children Easy
1/**
2 * [2236] Root Equals Sum of Children
3 *
4 * You are given the root of a binary tree that consists of exactly 3 nodes: the root, its left child, and its right child.
5 * Return true if the value of the root is equal to the sum of the values of its two children, or false otherwise.
6 *
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2022/04/08/graph3drawio.png" style="width: 281px; height: 199px;" />
9 * Input: root = [10,4,6]
10 * Output: true
11 * Explanation: The values of the root, its left child, and its right child are 10, 4, and 6, respectively.
12 * 10 is equal to 4 + 6, so we return true.
13 *
14 * Example 2:
15 * <img alt="" src="https://assets.leetcode.com/uploads/2022/04/08/graph3drawio-1.png" style="width: 281px; height: 199px;" />
16 * Input: root = [5,3,1]
17 * Output: false
18 * Explanation: The values of the root, its left child, and its right child are 5, 3, and 1, respectively.
19 * 5 is not equal to 3 + 1, so we return false.
20 *
21 *
22 * Constraints:
23 *
24 * The tree consists only of the root, its left child, and its right child.
25 * -100 <= Node.val <= 100
26 *
27 */
28pub struct Solution {}
29use crate::util::tree::{TreeNode, to_tree};
30
31// problem: https://leetcode.com/problems/root-equals-sum-of-children/
32// discuss: https://leetcode.com/problems/root-equals-sum-of-children/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36// Definition for a binary tree node.
37// #[derive(Debug, PartialEq, Eq)]
38// pub struct TreeNode {
39// pub val: i32,
40// pub left: Option<Rc<RefCell<TreeNode>>>,
41// pub right: Option<Rc<RefCell<TreeNode>>>,
42// }
43//
44// impl TreeNode {
45// #[inline]
46// pub fn new(val: i32) -> Self {
47// TreeNode {
48// val,
49// left: None,
50// right: None
51// }
52// }
53// }
54use std::rc::Rc;
55use std::cell::RefCell;
56impl Solution {
57 pub fn check_tree(root: Option<Rc<RefCell<TreeNode>>>) -> bool {
58 false
59 }
60}
61
62// submission codes end
63
64#[cfg(test)]
65mod tests {
66 use super::*;
67
68 #[test]
69 fn test_2236() {
70 }
71}
72
Back
© 2025 bowen.ge All Rights Reserved.