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)
}
相关推荐
ttwuai25 分钟前
AI 生成后台删除按钮后,MySQL 软删除和唯一索引怎么验
数据库·mysql·golang
runafterhit3 小时前
python基础语法命令(C程序员刷leetcode)
c语言·python·leetcode
青山木3 小时前
Hot 100 --- 全排列
java·数据结构·算法·leetcode·深度优先
Wang's Blog4 小时前
Go-Zero 项目开发19:基于 Kafka 的异步消息存储与转发实战
golang·kafka
小莫分享4 小时前
sshw:用交互搜索和 Web 配置高效管理 SSH Server
linux·运维·golang·开源·ssh
名字还没想好☜4 小时前
Go 结构体内存对齐:调整字段顺序,同样的字段省下 40% 内存
开发语言·后端·golang·go·内存对齐
玖玥拾4 小时前
LeetCode 13 罗马数字转整数
笔记·算法·leetcode
FfHUCisI5 小时前
sync.Mutex 互斥锁
golang
牛奔14 小时前
Go 如何打印调试深层或嵌套的结构体
开发语言·后端·golang
geovindu15 小时前
go: Iterative Algorithms
开发语言·后端·算法·golang·迭代算法