JAVA直接前序遍历树,没有采用栈和队列
求二叉树的前序遍历
http://www.nowcoder.com/questionTerminal/501fb3ca49bb4474bf5fa87274e884b4
import java.util.ArrayList;
public class Solution {
ArrayList<integer> list=new ArrayList<integer>();
public ArrayList<integer> preorderTraversal (TreeNode root) {
if(root!=null) {list.add(root.val);preorderTraversal (root.left);preorderTraversal (root.right);}
return list;
}
}</integer></integer></integer>