{3, 23, 11, null, null, 21, 99} 数组转换成二叉树
example:
3
/ \
23 11
/
21 99
public static TreeNode arrayToNode(Integer[] arr, int index) {
TreeNode treeNode = new TreeNode();
if (index <=arr.length - 1) {
treeNode.value = arr[index];
treeNode.leftChild = arrayToNode(arr, index * 2 + 1);
treeNode.rightNode = arrayToNode(arr, index * 2 + 2);
}
return treeNode;
}
public static class TreeNode {
public Integer value;
public TreeNode leftChild;
public TreeNode rightNode;
}