二叉搜索树节点最小距离
智能指针迭代器
use std::rc::Rc;use std::cell::RefCell;impl Solution {pub fn min_diff_in_bst(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {fn tile(maybe_node: Option<Rc<RefCell<TreeNode>>>, nums: &mut Vec<i32>) {if let Some(node) = maybe_node {tile(node.borrow_mut().left.take(), nums);nums.push(node.borrow().val);tile(node.borrow_mut().right.take(), nums);}}let mut nums = Vec::new();tile(root, &mut nums);nums.windows(2).map(|x| x[1]-x[0]).min().unwrap_or(0)}}
