// Definition for a binary tree node. #[derive(Debug, PartialEq, Eq)] pub struct TreeNode { pub val: i32, pub left: Option>>, pub right: Option>>, } impl TreeNode { #[inline] pub fn new(val: i32) -> Self { TreeNode { val, left: None, right: None } } } use std::rc::Rc; use std::cell::RefCell; struct Solution; impl Solution { pub fn sum_numbers(root: Option>>) -> i32 { Solution::sum_numbers_before(root, 0) } pub fn sum_numbers_before(root: Option>>, before: i32) -> i32 { let Some(node) = root else {return 0;}; let n = &node.borrow(); let mut sum = 0; if n.left.is_some() {sum += Solution::sum_numbers_before(n.left.clone(), before * 10 + n.val);} if n.right.is_some() {sum += Solution::sum_numbers_before(n.right.clone(), before * 10 + n.val);} sum } } fn main() { println!("Hello, world!"); }