impl Solution { fndfs(nums: &Vec<i32>, start: usize, end: usize) -> Option<Rc<RefCell<TreeNode>>> { if start > end { returnNone; } let (mut val, mut index) = (std::i32::MAX, 0); for i in start..end + 1 { if nums[i] > val { val = nums[i]; index = i; } }
letmut node = TreeNode::new(val); node.left = Self::dfs(nums, start, index - 1); node.right = Self::dfs(nums, index + 1, end); returnSome(Rc::new(RefCell::new(node))); }