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)
}
相关推荐
奔跑的废柴4 分钟前
LeetCode 513. 找树左下角的值 java题解
java·算法·leetcode
Awesome Baron7 分钟前
LeetCode hot 100 每日一题(7)--3. 无重复字符的最长子串
算法·leetcode·职场和发展
SsummerC12 分钟前
【leetcode100】组合总和
数据结构·python·算法·leetcode
winyh58 小时前
基于Golang的微服务——Consul
微服务·golang·consul
zhuyasen10 小时前
Go语言Viper配置详解:conf库优雅解析实战
后端·golang
一只_程序媛11 小时前
【leetcode hot 100 142】环形链表Ⅱ
算法·leetcode·链表
dengjiayue12 小时前
golang 高性能的 MySQL 数据导出
开发语言·mysql·golang
编程绿豆侠14 小时前
力扣HOT100之双指针:11. 盛最多水的容器
算法·leetcode·职场和发展
a李兆洋14 小时前
力扣 Hot 100 刷题记录 - LRU 缓存
算法·leetcode·缓存
2301_7665360515 小时前
刷leetcode hot100--动态规划3.11
算法·leetcode·动态规划