题目描述
题目链接:https://leetcode.cn/problems/binary-tree-preorder-traversal/description/
代码实现
class Solution {
List<Integer> l = new ArrayList<>();
public List<Integer> preorderTraversal(TreeNode root) {
preoder(root);
return l;
}
public void preoder(TreeNode root){
if(root==null){
return;
}
l.add(root.val);
preoder(root.left);
preoder(root.right);
}
}