diff options
author | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
commit | a96b65cbfad7f62f3db6b2eab105e4e25c0414c5 (patch) | |
tree | e2a2b3f49f9fb741be81415266ac93e74cff42ec /other/max_product_split_bt.rs | |
parent | 694ad5ed71edcb1deccab54b72d706b779918276 (diff) | |
download | leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.tar.gz leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.zip |
chore: remove old cpp and rust solutions
Diffstat (limited to 'other/max_product_split_bt.rs')
-rw-r--r-- | other/max_product_split_bt.rs | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/other/max_product_split_bt.rs b/other/max_product_split_bt.rs deleted file mode 100644 index 6aec321..0000000 --- a/other/max_product_split_bt.rs +++ /dev/null @@ -1,43 +0,0 @@ -#[derive(Debug, PartialEq, Eq)] -pub struct TreeNode { - pub val: i32, - pub left: Option<Rc<RefCell<TreeNode>>>, - pub right: Option<Rc<RefCell<TreeNode>>>, -} - -impl TreeNode { - #[inline] - pub fn new(val: i32) -> Self { - TreeNode { - val, - left: None, - right: None, - } - } -} - -use std::cell::RefCell; -use std::rc::Rc; -const MOD: i64 = 1_000_000_007; -impl Solution { - pub fn max_product(root: Option<Rc<RefCell<TreeNode>>>) -> i32 { - let mut sums = Vec::new(); - Self::dfs(&root, &mut sums); - ((0..sums.len() - 1) - .map(|i| sums[i] * (sums[sums.len() - 1] - sums[i])) - .max() - .unwrap() - % MOD) as i32 - } - fn dfs(node: &Option<Rc<RefCell<TreeNode>>>, sums: &mut Vec<i64>) -> i64 { - if let Some(n) = node { - let sum = n.borrow().val as i64 - + Self::dfs(&n.borrow().left, sums) - + Self::dfs(&n.borrow().right, sums); - sums.push(sum); - sum - } else { - 0 - } - } -} |