1
from collections import deque6
def __init__(self, root: TreeNode):10
self.parent_keeper = deque([root])14
cur = self.parent_keeper[0]20
self.parent_keeper.append(cur.left)24
self.parent_keeper.append(cur.right)26
# cur is completed with two child, pop out27
self.parent_keeper.popleft()30
# parent of next insertion is found, stop34
# parent of next insertion is found, stop37
def insert(self, v: int) -> int:39
parent = self.parent_keeper[0]41
# Insert with leftward compact, to meet the definition of complete binary tree44
parent.left = TreeNode(v)45
self.parent_keeper.append(parent.left)47
parent.right = TreeNode(v)48
self.parent_keeper.append(parent.right)50
# current parent is completed with two child now, pop parent from parent keeper on the head51
self.parent_keeper.popleft()55
def get_root(self) -> TreeNode: