1302. Deepest Leaves Sum Medium
1/**
2 * [1302] Deepest Leaves Sum
3 *
4 * Given the root of a binary tree, return the sum of values of its deepest leaves.
5 *
6 * Example 1:
7 * <img alt="" src="https://assets.leetcode.com/uploads/2019/07/31/1483_ex1.png" style="width: 273px; height: 265px;" />
8 * Input: root = [1,2,3,4,5,null,6,7,null,null,null,null,8]
9 * Output: 15
10 *
11 * Example 2:
12 *
13 * Input: root = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5]
14 * Output: 19
15 *
16 *
17 * Constraints:
18 *
19 * The number of nodes in the tree is in the range [1, 10^4].
20 * 1 <= Node.val <= 100
21 *
22 */
23pub struct Solution {}
24use crate::util::tree::{TreeNode, to_tree};
25
26// problem: https://leetcode.com/problems/deepest-leaves-sum/
27// discuss: https://leetcode.com/problems/deepest-leaves-sum/discuss/?currentPage=1&orderBy=most_votes&query=
28
29// submission codes start here
30
31// Definition for a binary tree node.
32// #[derive(Debug, PartialEq, Eq)]
33// pub struct TreeNode {
34// pub val: i32,
35// pub left: Option<Rc<RefCell<TreeNode>>>,
36// pub right: Option<Rc<RefCell<TreeNode>>>,
37// }
38//
39// impl TreeNode {
40// #[inline]
41// pub fn new(val: i32) -> Self {
42// TreeNode {
43// val,
44// left: None,
45// right: None
46// }
47// }
48// }
49use std::rc::Rc;
50use std::cell::RefCell;
51impl Solution {
52 pub fn deepest_leaves_sum(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
53 0
54 }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_1302() {
65 }
66}
67
Back
© 2025 bowen.ge All Rights Reserved.