404. Sum of Left Leaves Easy
1/**
2 * [404] Sum of Left Leaves
3 *
4 * Given the root of a binary tree, return the sum of all left leaves.
5 * A leaf is a node with no children. A left leaf is a leaf that is the left child of another node.
6 *
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2021/04/08/leftsum-tree.jpg" style="width: 277px; height: 302px;" />
9 * Input: root = [3,9,20,null,null,15,7]
10 * Output: 24
11 * Explanation: There are two left leaves in the binary tree, with values 9 and 15 respectively.
12 *
13 * Example 2:
14 *
15 * Input: root = [1]
16 * Output: 0
17 *
18 *
19 * Constraints:
20 *
21 * The number of nodes in the tree is in the range [1, 1000].
22 * -1000 <= Node.val <= 1000
23 *
24 */
25pub struct Solution {}
26use crate::util::tree::{TreeNode, to_tree};
27
28// problem: https://leetcode.com/problems/sum-of-left-leaves/
29// discuss: https://leetcode.com/problems/sum-of-left-leaves/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 sum_of_left_leaves(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
55 0
56 }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_404() {
67 }
68}
69
Back
© 2025 bowen.ge All Rights Reserved.