#958
Check Completeness of a Binary Tree
specialist · 720 · lc medium +30 · verified · 59% accepted · 4,532 likes · top 56%
Description
A complete binary tree has all levels entirely filled except possibly the deepest, where nodes are packed as far left as possible. Given the root of a binary tree, return true if the tree is complete, false otherwise.
Example 1:
Input: root = [1,2,3,4,5,6]
Output: true
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.
Example 2:
Input: root = [1,2,3,4,5,null,7]
Output: false
Explanation: The node with value 7 isn't as far left as possible.
Code
1
2
3
4
5
6
7
8
9