144. Binary Tree Preorder Traversal


  • 0
    H
    func preorderTraversal(root *TreeNode) []int {
    	l := make([]int, 0, 3)
    	if root == nil {
    		return l
    	}
    
    	l = append(l, root.Val)
    	l = append(l, preorderTraversal(root.Left)...)
    	l = append(l, preorderTraversal(root.Right)...)
    
    	return l
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.