题解 | #二叉树的前序遍历#
二叉树的前序遍历
http://www.nowcoder.com/practice/5e2135f4d2b14eb8a5b06fab4c938635
//golang递归
func preorderTraversal( root *TreeNode ) []int {
// write code here
res:=make([]int,0)
preOrder(&res,root)
return res
}
func preOrder(res *[]int,root *TreeNode){
if root==nil{
return
}
*res=append(*res, root.Val)
preOrder(res,root.Left)
preOrder(res,root.Right)
}