897. Increasing Order Search Tree Easy

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



1/**
2 * [897] Increasing Order Search Tree
3 *
4 * Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child.
5 *  
6 * Example 1:
7 * <img alt="" src="https://assets.leetcode.com/uploads/2020/11/17/ex1.jpg" style="width: 600px; height: 350px;" />
8 * Input: root = [5,3,6,2,4,null,8,1,null,null,null,7,9]
9 * Output: [1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9]
10 * 
11 * Example 2:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2020/11/17/ex2.jpg" style="width: 300px; height: 114px;" />
13 * Input: root = [5,1,7]
14 * Output: [1,null,5,null,7]
15 * 
16 *  
17 * Constraints:
18 * 
19 * 	The number of nodes in the given tree will be in the range [1, 100].
20 * 	0 <= Node.val <= 1000
21 * 
22 */
23pub struct Solution {}
24use crate::util::tree::{TreeNode, to_tree};
25
26// problem: https://leetcode.com/problems/increasing-order-search-tree/
27// discuss: https://leetcode.com/problems/increasing-order-search-tree/discuss/?currentPage=1&orderBy=most_votes&query=
28
29// submission codes start here
30
31// Definition for a binary tree node.
32// #[derive(Debug, PartialEq, Eq)]
33// pub struct TreeNode {
34//   pub val: i32,
35//   pub left: Option<Rc<RefCell<TreeNode>>>,
36//   pub right: Option<Rc<RefCell<TreeNode>>>,
37// }
38// 
39// impl TreeNode {
40//   #[inline]
41//   pub fn new(val: i32) -> Self {
42//     TreeNode {
43//       val,
44//       left: None,
45//       right: None
46//     }
47//   }
48// }
49use std::rc::Rc;
50use std::cell::RefCell;
51impl Solution {
52    pub fn increasing_bst(root: Option<Rc<RefCell<TreeNode>>>) -> Option<Rc<RefCell<TreeNode>>> {
53        Some(Rc::new(RefCell::new(TreeNode::new(0))))
54    }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn test_897() {
65    }
66}
67


Back
© 2025 bowen.ge All Rights Reserved.