783. Minimum Distance Between BST Nodes Easy

@problem@discussion
#Tree#Depth-First Search#Breadth-First Search#Binary Search Tree#Binary Tree



1/**
2 * [783] Minimum Distance Between BST Nodes
3 *
4 * Given the root of a Binary Search Tree (BST), return the minimum difference between the values of any two different nodes in the tree.
5 *  
6 * Example 1:
7 * <img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg" style="width: 292px; height: 301px;" />
8 * Input: root = [4,2,6,1,3]
9 * Output: 1
10 * 
11 * Example 2:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2021/02/05/bst2.jpg" style="width: 282px; height: 301px;" />
13 * Input: root = [1,0,48,null,null,12,49]
14 * Output: 1
15 * 
16 *  
17 * Constraints:
18 * 
19 * 	The number of nodes in the tree is in the range [2, 100].
20 * 	0 <= Node.val <= 10^5
21 * 
22 *  
23 * Note: This question is the same as 530: <a href="https://leetcode.com/problems/minimum-absolute-difference-in-bst/" target="_blank">https://leetcode.com/problems/minimum-absolute-difference-in-bst/</a>
24 * 
25 */
26pub struct Solution {}
27use crate::util::tree::{TreeNode, to_tree};
28
29// problem: https://leetcode.com/problems/minimum-distance-between-bst-nodes/
30// discuss: https://leetcode.com/problems/minimum-distance-between-bst-nodes/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34// Definition for a binary tree node.
35// #[derive(Debug, PartialEq, Eq)]
36// pub struct TreeNode {
37//   pub val: i32,
38//   pub left: Option<Rc<RefCell<TreeNode>>>,
39//   pub right: Option<Rc<RefCell<TreeNode>>>,
40// }
41// 
42// impl TreeNode {
43//   #[inline]
44//   pub fn new(val: i32) -> Self {
45//     TreeNode {
46//       val,
47//       left: None,
48//       right: None
49//     }
50//   }
51// }
52use std::rc::Rc;
53use std::cell::RefCell;
54impl Solution {
55    pub fn min_diff_in_bst(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
56        0
57    }
58}
59
60// submission codes end
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65
66    #[test]
67    fn test_783() {
68    }
69}
70


Back
© 2025 bowen.ge All Rights Reserved.