将数字切片转换成字符串切片,自定义排序函数,当两个数拼接起来,谁小谁在前面
func minNumber(nums []int) string {
str := []string{}
for _, v := range nums {
str = append(str, strconv.Itoa(v))
}
sort.Slice(str, func(i, j int) bool {
str1 := str[i] + str[j]
str2 := str[j] + str[i]
return str1 < str2
})
return strings.Join(str, "")
}