Given the root of a binary tree, return true if it is a complete binary tree. In a complete binary tree every level except possibly the last is completely filled, and all nodes in the last level are as far left as possible.
Given the root of a binary tree, return true if it is a complete binary tree. In a complete binary tree every level except possibly the last is completely filled, and all nodes in the last level are as far left as possible.
Example 1:
Input: {"root":[1,2,3,4,5,6]}
Output: true
Constraints:
The number of nodes in the tree is in the range [1,100].
1≤Node.val≤1000
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"root":[1,2,3,4,5,6]}
Put the root 1 on the queue. A BFS visits slots in level order, so a complete tree shows every node before any empty slot.