add new solutions

This commit is contained in:
kanna5 2026-01-27 18:38:43 +09:00
parent 67cad91898
commit 81cc2d3ba6
No known key found for this signature in database
19 changed files with 693 additions and 14 deletions

View file

@ -0,0 +1,24 @@
package q144
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
func walk(node *TreeNode, ret *[]int) {
if node == nil {
return
}
*ret = append(*ret, node.Val)
walk(node.Left, ret)
walk(node.Right, ret)
}
func preorderTraversal(root *TreeNode) []int {
ret := []int{}
walk(root, &ret)
return ret
}
var _ = preorderTraversal