/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ funcsortedArrayToBST(nums []int) *TreeNode { if nums==nil || len(nums)==0{ returnnil } ret:=new(TreeNode) middle:=len(nums)/2 ret.Val=nums[middle] ret.Left=sortedArrayToBST(nums[:middle]) ret.Right=sortedArrayToBST(nums[middle+1:]) return ret }