package leetcode
import (
"github.com/halfrost/LeetCode-Go/structures"
)
type TreeNode = structures.TreeNode
func kthSmallest(root *TreeNode, k int) int {
res, count := 0, 0
inorder230(root, k, &count, &res)
return res
}
func inorder230(node *TreeNode, k int, count *int, ans *int) {
if node != nil {
inorder230(node.Left, k, count, ans)
*count++
if *count == k {
*ans = node.Val
return
}
inorder230(node.Right, k, count, ans)
}
}