添加新题目

This commit is contained in:
2025-08-26 06:18:10 +08:00
parent e1546166a3
commit 72f4dca9ed
18 changed files with 485 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
package main
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
func main() {
}
func kthSmallest(root *TreeNode, k int) int {
var helper func(root *TreeNode) []int
helper = func(root *TreeNode) []int {
if root == nil {
return []int{}
}
tmp := make([]int, 0)
tmp = append(tmp, helper(root.Left)...)
tmp = append(tmp, root.Val)
tmp = append(tmp, helper(root.Right)...)
return tmp
}
res := helper(root)
return res[k-1]
}