use std::rc::Rc; use std::cell::RefCell; use std::cmp::max; impl Solution { pubfnbtree_game_winning_move(root: Option<Rc<RefCell<TreeNode>>>, n: i32, x: i32) -> bool { fncount_sub_tree_nodes(node: Option<&Rc<RefCell<TreeNode>>>, x : i32, left : &muti32, right : &muti32) -> i32 { ifletSome(n) = node { let l = count_sub_tree_nodes(n.borrow().left.as_ref(), x, left, right); let r = count_sub_tree_nodes(n.borrow().right.as_ref(), x, left, right); if x == n.borrow().val { *left = l; *right = r; } return l + r + 1; } else { return0; } };
letmut left = 0; letmut right = 0; let count = count_sub_tree_nodes(root.as_ref(), x, &mut left, &mut right); return max(max(left, right), n - left - right - 1) > n / 2; } }