/*
 * 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) {
        // write code here
        
        int[][] result = new int[3][getNums(root)];
       
        order(result,root);
        return result;
        
    }
            //先序
    int flag = 0,flag1= 0,flag2 = 0;
    public void order(int[][] data,TreeNode node){
        if(node == null){
            return;
        }
        data[0][flag ++] = node.val;
        order(data, node.left);
        data[1][flag1 ++] = node.val;
        order(data, node.right);
        data[2][flag2 ++] = node.val;
    }
      public int getNums(TreeNode root){
         if(root == null){
             return 0;
         }
          return 1 +getNums(root.left) +getNums(root.right);
    }
}