https://leetcode-cn.com/problems/binary-tree-preorder-traversal/ 
class Solution {
public List<Integer> preorderTraversal(TreeNode root) {
List<Integer> res = new ArrayList<Integer>();
preorder(root,res);
System.out.print(res);
return res;
}
public void preorder(TreeNode root,List<Integer> res){
if(root==null){
return;
}
res.add(root.val);
System.out.print(res);
preorder(root.left,res);
preorder(root.right,res);
}
}

https://programmercarl.com/%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E9%80%92%E5%BD%92%E9%81%8D%E5%8E%86.html
|