### 将树转化为数组 - static List kminArray(TreeNode root){ List array=new ArrayList<>(); if(root==null){ return array; } //利用递归法,将树转化为数组 array.addAll(kminArray(root.left));//牛 array.add(root.val); array.addAll(kminArray(root.right)); return array; } ### 树的创建方法-队列 - static TreeNode createTree(int rootIndex, Integer[] values) { if (rootIndex >= values.length) { return null; } if (values[rootIndex] == null) { return null; } TreeNode rootNode = new TreeNode(); rootNode.val = values[rootIndex]; rootNode.left = createTree(2 * rootIndex + 1, values); rootNode.right = createTree(2 * rootIndex + 2, values); return rootNode;//返回根节点 } -