Given a list of integers, build a complete binary tree using the list as its node weight. Note that 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.
Sample Input:
[1, 2, 3, 4, 5, 6, 6, 6, 6]
Sample Output:
<1, <2, <4, <6, None, None>, <6, None, None>>, <5, None, None>>, <3, <6, None, None>, <6, None, None>>>
数据结构和算法:初级练习题 #33 – 构建二叉树
给定一个数组,用数组里的数值作为二叉树的节点重量来创建一颗二叉树。
输入样例:
[1, 2, 3, 4, 5, 6, 6, 6, 6]
输出样例:
<1, | ||||
<2, | ||||
<4, | ||||
<6, None, None>, | ||||
<6, None, None> | ||||
>, | ||||
<5, None, None> | ||||
>, | ||||
<3, | ||||
<6, None, None>, | ||||
<6, None, None>, | ||||
> | ||||
> |