Given the root of a complete binary tree, return the total number of nodes in the tree. Pattern focus: Recursive Tree Metrics. Use the structure of a complete tree to count nodes efficiently.
root = complete binary tree root
total number of nodes in the tree
Example 1:
Input:
root = [1,2,3,4,5,6]
Output:
6
Explanation:
The tree contains six nodes.
Example 2:
Input:
root = [1,2,3,4,5,6,7]
Output:
7
Explanation:
A perfect complete tree of height 3 has 7 nodes.