(TreeNode root,List<Integer> list)
| 1 | class Solution { |
| 2 | public void preorder(TreeNode root,List<Integer> list) |
| 3 | { |
| 4 | if(root==null) return; |
| 5 | list.add(root.val); |
| 6 | preorder(root.left,list); |
| 7 | preorder(root.right,list); |
| 8 | } |
| 9 | public List<Integer> preorderTraversal(TreeNode root) { |
| 10 | List<Integer> list = new ArrayList<Integer>(); |
| 11 | preorder(root,list); |