题解 | #最大数#
最大数
http://www.nowcoder.com/practice/fc897457408f4bbe9d3f87588f497729
package main
import (
"fmt"
"sort"
"strings"
)
func solve( nums []int ) string {
// write code here
n := len(nums)
strs := make([]string,n)
for i, _ := range nums {
strs[i] = fmt.Sprintf("%d", nums[i])
}
sort.Slice(strs, func(i, j int) bool {
return strs[i] + strs[j] > strs[j] + strs[i] //这里变一下
})
if strs[0][0] == '0' {
return "0"
}
return strings.Join(strs,"")
}