这的建立普通二叉会超出范围,改为如下可以: //建立普通的二叉树 public static TreeNode buildBinaryTree(int[] array, int index) { TreeNode root = null; if (index < array.length) { root = new TreeNode(array[index]); // 对于顺序存储的完全二叉树,如果某个节点的索引为index,其对应的左子树的索引为2*index+1,右子树为2*index+1 root.left = buildBinaryTree(array,2 * index + 1); root.right = buildBinaryTree(array,2 * index + 2); } return root; }
点赞 评论

相关推荐

牛客网
牛客企业服务