2773. Height of Special Binary Tree
You are given a
root``n
nodes. The nodes of the special binary tree are numbered from1
ton
. Suppose the tree hask
leaves in the following order:b1 < b2 < ... < bk
.
bi
, the following conditions hold:
- The right child of
bi
isbi + 1
ifi < k
, andb1
otherwise.- The left child of
bi
isbi - 1
ifi > 1
, andbk
otherwise.Return the height of the given tree.
Note: The height of a binary tree is the length of the longest path from the root to any other node.
1 | /** |