题目:
题解:
func getSuccessor(node *TreeNode) *TreeNode {succ := node.Rightfor succ.Left != nil && succ.Left != node {succ = succ.Left}return succ
}func convertBST(root *TreeNode) *TreeNode {sum := 0node := rootfor node != nil {if node.Right == nil {sum += node.Valnode.Val = sumnode = node.Left} else {succ := getSuccessor(node)if succ.Left == nil {succ.Left = nodenode = node.Right} else {succ.Left = nilsum += node.Valnode.Val = sumnode = node.Left}}}return root
}