144. Binary Tree Preorder Traversal
没什么要说的
1 public List<Integer> preorderTraversal(TreeNode root) { 2 List<Integer> res = new ArrayList<Integer>(); 3 if(root == null) { 4 return res; 5 } 6 dfs(root, res); 7 return res; 8 } 9 10 private void dfs(TreeNode root, List<Integer> res) { 11 if(root == null) { 12 return; 13 } 14 res.add(root.val); 15 dfs(root.left, res); 16 dfs(root.right, res); 17 }