222. Count Complete Tree Nodes
题目大意
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.
中文释义
给定一个完全二叉树的根节点,返回树中节点的数量。
根据维基百科,除最后一层外,完全二叉树的每一层都完全填满,且最后一层的所有节点尽可能地靠左。最后一层 h 可以包含 1 到 2^h 个节点。
设计一个时间复杂度低于 O(n) 的算法。
示例
示例 1:
输入: root
= [1,2,3,4,5,6]
输出: 6
示例 2:
输入: root
= []
输出: 0
示例 3:
输入: root
&#