894. All Possible Full Binary Trees Medium

@problem@discussion
#Dynamic Programming#Tree#Recursion#Memoization#Binary Tree



1/**
2 * [894] All Possible Full Binary Trees
3 *
4 * Given an integer n, return a list of all possible full binary trees with n nodes. Each node of each tree in the answer must have Node.val == 0.
5 * Each element of the answer is the root node of one possible tree. You may return the final list of trees in any order.
6 * A full binary tree is a binary tree where each node has exactly 0 or 2 children.
7 *  
8 * Example 1:
9 * <img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/08/22/fivetrees.png" style="width: 700px; height: 400px;" />
10 * Input: n = 7
11 * Output: [[0,0,0,null,null,0,0,null,null,0,0],[0,0,0,null,null,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,null,null,null,null,0,0],[0,0,0,0,0,null,null,0,0]]
12 * 
13 * Example 2:
14 * 
15 * Input: n = 3
16 * Output: [[0,0,0]]
17 * 
18 *  
19 * Constraints:
20 * 
21 * 	1 <= n <= 20
22 * 
23 */
24pub struct Solution {}
25use crate::util::tree::{TreeNode, to_tree};
26
27// problem: https://leetcode.com/problems/all-possible-full-binary-trees/
28// discuss: https://leetcode.com/problems/all-possible-full-binary-trees/discuss/?currentPage=1&orderBy=most_votes&query=
29
30// submission codes start here
31
32// Definition for a binary tree node.
33// #[derive(Debug, PartialEq, Eq)]
34// pub struct TreeNode {
35//   pub val: i32,
36//   pub left: Option<Rc<RefCell<TreeNode>>>,
37//   pub right: Option<Rc<RefCell<TreeNode>>>,
38// }
39// 
40// impl TreeNode {
41//   #[inline]
42//   pub fn new(val: i32) -> Self {
43//     TreeNode {
44//       val,
45//       left: None,
46//       right: None
47//     }
48//   }
49// }
50use std::rc::Rc;
51use std::cell::RefCell;
52impl Solution {
53    pub fn all_possible_fbt(n: i32) -> Vec<Option<Rc<RefCell<TreeNode>>>> {
54        vec![]
55    }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    #[test]
65    fn test_894() {
66    }
67}
68


Back
© 2025 bowen.ge All Rights Reserved.