1305. All Elements in Two Binary Search Trees Medium

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



1/**
2 * [1305] All Elements in Two Binary Search Trees
3 *
4 * Given two binary search trees root1 and root2, return a list containing all the integers from both trees sorted in ascending order.
5 *  
6 * Example 1:
7 * <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18/q2-e1.png" style="width: 457px; height: 207px;" />
8 * Input: root1 = [2,1,4], root2 = [1,0,3]
9 * Output: [0,1,1,2,3,4]
10 * 
11 * Example 2:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18/q2-e5-.png" style="width: 352px; height: 197px;" />
13 * Input: root1 = [1,null,8], root2 = [8,1]
14 * Output: [1,1,8,8]
15 * 
16 *  
17 * Constraints:
18 * 
19 * 	The number of nodes in each tree is in the range [0, 5000].
20 * 	-10^5 <= Node.val <= 10^5
21 * 
22 */
23pub struct Solution {}
24use crate::util::tree::{TreeNode, to_tree};
25
26// problem: https://leetcode.com/problems/all-elements-in-two-binary-search-trees/
27// discuss: https://leetcode.com/problems/all-elements-in-two-binary-search-trees/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 get_all_elements(root1: Option<Rc<RefCell<TreeNode>>>, root2: Option<Rc<RefCell<TreeNode>>>) -> Vec<i32> {
53        vec![]
54    }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn test_1305() {
65    }
66}
67


Back
© 2025 bowen.ge All Rights Reserved.