1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| // @Title: 把数组排成最小的数 (把数组排成最小的数 LCOF)
// @Author: 15816537946@163.com
// @Date: 2022-02-19 18:58:47
// @Runtime: 4 ms
// @Memory: 3 MB
func minNumber(nums []int) string {
sort.Slice(nums, func(i,j int) bool {
x := fmt.Sprintf("%d%d",nums[i],nums[j])
y := fmt.Sprintf("%d%d",nums[j],nums[i])
return x <y
})
res := ""
for i :=0;i<len(nums);i++ {
res += fmt.Sprintf("%d",nums[i])
}
return res
}
|