Golang | Leetcode Golang题解之第179题最大数

题目:

题解:

Go 复制代码
func largestNumber(nums []int) string {
    sort.Slice(nums, func(i, j int) bool {
        x, y := nums[i], nums[j]
        sx, sy := 10, 10
        for sx <= x {
            sx *= 10
        }
        for sy <= y {
            sy *= 10
        }
        return sy*x+y > sx*y+x
    })
    if nums[0] == 0 {
        return "0"
    }
    ans := []byte{}
    for _, x := range nums {
        ans = append(ans, strconv.Itoa(x)...)
    }
    return string(ans)
}
相关推荐
ifanatic16 小时前
[每周一更]-(第159期):Go 工程师视角:容器化技术(Docker/Kubernetes)与CI/CD流程的应用场景
docker·golang·kubernetes
张烫麻辣亮。17 小时前
golang-gin包
开发语言·golang·gin
Sally璐璐17 小时前
Go正则表达式实战指南
数据库·mysql·golang
yuluo_YX17 小时前
Go Style 代码风格规范
开发语言·后端·golang
qq_1728055919 小时前
Go 自建库的使用教程与测试
开发语言·后端·golang
共享家952721 小时前
优先搜索(DFS)实战
算法·leetcode·深度优先
007php0071 天前
某大厂MySQL面试之SQL注入触点发现与SQLMap测试
数据库·python·sql·mysql·面试·职场和发展·golang
flashlight_hi1 天前
LeetCode 分类刷题:2563. 统计公平数对的数目
python·算法·leetcode
雨中散步撒哈拉1 天前
13、做中学 | 初一下期 Golang数组与切片
开发语言·后端·golang
0wioiw01 天前
Go基础(③Cobra)
开发语言·后端·golang