1、sort.Slice排序
字符串数组排序
sort.Sort(sort.StringSlice(strs))
数组排序
sort.Slice(nums,func(i,j int)bool{
return nums[i]<nums[j]
})
2、将两个int合并为string
//将int型a,b合并为string str1
str1:=fmt.Sprintf("%d%d",a,b)
3、内部函数的设立(以树的最大深度为例)
//声明
var maxDepth func(root *TreeNode) int
//定义
maxDepth = func(root *TreeNode) int {
if root!=nil{
left:=maxDepth(root.Left)
right:=maxDepth(root.Right)
return max(left,right)+1
}
return 0
}
//实现
maxDepth(root)
---------------------------
func max(x,y int)int{
if x>y {
return x
}
return y
}