标签:
前序遍历,递归,先遍历根节点,再遍历左节点
/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNode left; * public TreeNode right; * public TreeNode(int x) { val = x; } * } */ public class Solution { public void PreOrder(TreeNode root, IList<int> path) { if(root != null) { path.Add(root.val); PreOrder(root.left, path); PreOrder(root.right, path); } } public IList<int> PreorderTraversal(TreeNode root) { List<int> result = new List<int>(); PreOrder(root, result); return result; } }
144_Binary Tree Preorder Traversal
标签:
原文地址:http://www.cnblogs.com/Anthony-Wang/p/5090989.html