958. Check Completeness of a Binary Tree Medium

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



1/**
2 * [958] Check Completeness of a Binary Tree
3 *
4 * Given the root of a binary tree, determine if it is a complete binary tree.
5 * In a <a href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees" target="_blank">complete binary tree</a>, every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2^h nodes inclusive at the last level h.
6 *  
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2018/12/15/complete-binary-tree-1.png" style="width: 180px; height: 145px;" />
9 * Input: root = [1,2,3,4,5,6]
10 * Output: true
11 * Explanation: Every level before the last is full (ie. levels with node-values {1} and {2, 3}), and all nodes in the last level ({4, 5, 6}) are as far left as possible.
12 * 
13 * Example 2:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2018/12/15/complete-binary-tree-2.png" style="width: 200px; height: 145px;" />
15 * Input: root = [1,2,3,4,5,null,7]
16 * Output: false
17 * Explanation: The node with value 7 isn't as far left as possible.
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	The number of nodes in the tree is in the range [1, 100].
23 * 	1 <= Node.val <= 1000
24 * 
25 */
26pub struct Solution {}
27use crate::util::tree::{TreeNode, to_tree};
28
29// problem: https://leetcode.com/problems/check-completeness-of-a-binary-tree/
30// discuss: https://leetcode.com/problems/check-completeness-of-a-binary-tree/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 is_complete_tree(root: Option<Rc<RefCell<TreeNode>>>) -> bool {
56        false
57    }
58}
59
60// submission codes end
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65
66    #[test]
67    fn test_958() {
68    }
69}
70


Back
© 2025 bowen.ge All Rights Reserved.