import java.util.*;
public class Main {
/**
//该段代码仅用于调试,提交时请注释该段代码
class TreeNode<T> {
public T data;
public TreeNode<T> left;
public TreeNode<T> right;
}
*/
public void pre(TreeNode<Integer> root,List<Integer> list){
if(root != null){
pre(root.left,list);
list.add(root.data);
pre(root.right,list);
}
}
public int[] solution(TreeNode<Integer> root) {
List<Integer> list = new ArrayList<>();
pre(root,list);
if(list == null || list.isEmpty() ){
return null;
}
int[] a = new int[list.size()];
for (int i = 0; i < a.length; i++) {
a[i] = list.get(i);
}
return a;
}
}