import java.util.*;
/*
- public class TreeNode {
- int val = 0;
- TreeNode left = null;
- TreeNode right = null;
- } */
/*
-
public class TreeNode {
-
int val = 0;
-
TreeNode left = null;
-
TreeNode right = null;
-
} / public class Solution { /* *
-
@param root TreeNode类 the root of binary tree
-
@return int整型二维数组 */ public int[][] threeOrders (TreeNode root) { List list1=new ArrayList<>(); List list2=new ArrayList<>(); List list3=new ArrayList<>(); preOrder(root,list1); inOrder(root,list2); postOrder(root,list3); int[][] array=new int[3][list1.size()]; for(int a=0;a<list1.size();a++){ array[0][a]=list1.get(a); array[1][a]=list2.get(a); array[2][a]=list3.get(a); } return array;
// write code here }
public void preOrder(TreeNode root,List list){ if(root==null){ return; } list.add(root.val); preOrder(root.left,list); preOrder(root.right,list);
} public void inOrder(TreeNode root,List list){ if(root==null){ return; } inOrder(root.left,list); list.add(root.val); inOrder(root.right,list);
} public void postOrder(TreeNode root,List list){ if(root==null){ return; }
postOrder(root.left,list); postOrder(root.right,list); list.add(root.val);} }
-



京公网安备 11010502036488号