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)
}
相关推荐
To_OC14 小时前
LC 17 电话号码的字母组合:我的回溯算法,就是从这道题开窍的
javascript·算法·leetcode
海石1 天前
【JS击败90%】前缀和+定长滑动窗口
算法·leetcode
Tisfy1 天前
LeetCode 2685.统计完全连通分量的数量:DFS求每个连通块的边点数
算法·leetcode·深度优先··题解·连通图·全连通分量
海石1 天前
1次遍历,空间复杂度击败100%,时间复杂度击败85%
算法·leetcode
lueluelue471 天前
LeetCode:滑动窗口
数据结构·算法·leetcode
Generalzy1 天前
从本地 Demo 到生产级检索:Milvus 学习笔记(2)
golang·milvus
小高Baby@1 天前
单链表的删操作
数据结构·算法·golang
青山木1 天前
Hot 100 --- 二叉树与递归
java·数据结构·算法·leetcode·深度优先
tachibana21 天前
hot100 将有序数组转换为二叉搜索树(108)
java·数据结构·算法·leetcode
张3231 天前
Go语言基础 Map 函数值 闭包
开发语言·golang