标签:
题目描述:
/**
* 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 IList<int> PreorderTraversal(TreeNode root)
{
var ret = new List<int>();
Travel(root, ref ret);
return ret;
}
private void Travel(TreeNode current, ref List<int> result)
{
if(current == null){
return ;
}
result.Add(current.val);
Travel(current.left, ref result);
Travel(current.right, ref result);
}
}版权声明:本文为博主原创文章,未经博主允许不得转载。
LeetCode -- Binary Tree Preorder Traversal
标签:
原文地址:http://blog.csdn.net/lan_liang/article/details/49188153