/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/functrimBST(root*TreeNode,lowint,highint)*TreeNode{ifroot==nil{returnnil}ifroot.Val<low{returntrimBST(root.Right,low,high)}elseifroot.Val>high{returntrimBST(root.Left,low,high)}elseifroot.Val==low{root.Left=nilroot.Right=trimBST(root.Right,low+1,high)returnroot}elseifroot.Val==high{root.Right=nilroot.Left=trimBST(root.Left,low,high-1)returnroot}else{root.Left=trimBST(root.Left,low,root.Val-1)root.Right=trimBST(root.Right,root.Val+1,high)returnroot}}