Practice Count Complete Tree Nodes
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given the root of a complete binary tree, return the number of the nodes in the tree. According to Wikipedia, every level, except possibly the last, is completely filled in a complete binary tree, 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. Design an algorithm that runs in less than O(n) time complexity.
Source: Count Complete Tree Nodes on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
root = [1,2,3,4,5,6]
6
# Example 2
root = []
0
# Example 3
root = [1]
1
Constraints
Related LeetCode Problems
Practice more problems similar to Count Complete Tree Nodes.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.