A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.
Write a data structure
CBTInserter that is initialized with a complete binary tree and supports the following operations:
CBTInserter(TreeNode root)initializes the data structure on a given tree with head node
CBTInserter.insert(int v)will insert a
TreeNodeinto the tree with value
node.val = vso that the tree remains complete, and returns the value of the parent of the inserted
CBTInserter.get_root()will return the head node of the tree.
Input: inputs = ["CBTInserter","insert","get_root"], inputs = [[],,] Output: [null,1,[1,2]]
Input: inputs = ["CBTInserter","insert","insert","get_root"], inputs = [[[1,2,3,4,5,6]],,,] Output: [null,3,4,[1,2,3,4,5,6,7,8]]
CBTInserter.insertis called at most
10000times per test case.