LeetCode 179. 最大数
题目描述
✅ 179. 最大数
思路分析
自定义排序
参考代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
func largestNumber(nums []int) string {
strs := make([]string, len(nums))
for i := 0; i < len(nums); i++ {
strs[i] = strconv.Itoa(nums[i])
}
sort.Slice(strs, func(i, j int) bool {
return strs[i]+strs[j] > strs[j]+strs[i]
})
if strs[0] == "0" {
return "0"
}
var res string
for i := 0; i < len(nums); i++ {
res += strs[i]
}
return res
}
1
write your code here
CC BY-NC-SA 4.0
许可协议,转载请注明出处!
本博客所有文章除特别声明外,均采用