Skip to content

Commit

Permalink
feat: 144. Binary Tree Preorder Traversal
Browse files Browse the repository at this point in the history
Signed-off-by: ashing <axingfly@gmail.com>
  • Loading branch information
ronething committed Feb 11, 2024
1 parent 37dd604 commit 3471040
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions leetcode_daily/20240211/144. Binary Tree Preorder Traversal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package _0240211

import "algorithm/template"

type TreeNode = template.TreeNode

func preorderTraversal(root *TreeNode) []int {
var res []int
var sub func(n *TreeNode)
sub = func(n *TreeNode) {
if n == nil {
return
}
res = append(res, n.Val)
sub(n.Left)
sub(n.Right)
}
sub(root)
return res
}

0 comments on commit 3471040

Please sign in to comment.