思路
简单递归
code
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
func trimBST(root *TreeNode, L int, R int) *TreeNode {
if root == nil {
return root
}
if root.Val > R {
return trimBST(root.Left, L, R)
}
if root.Val < L {
return trimBST(root.Right, L, R)
}
root.Left = trimBST(root.Left, L, R)
root.Right = trimBST(root.Right, L, R)
return root
}
更多内容请移步我的repo:https://github.com/anakin/golang-leetcode