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)
}
相关推荐
熬了夜的程序员8 分钟前
【LeetCode】101. 对称二叉树
算法·leetcode·链表·职场和发展·矩阵
Kuo-Teng1 小时前
LeetCode 73: Set Matrix Zeroes
java·算法·leetcode·职场和发展
葵续浅笑2 小时前
LeetCode - 杨辉三角 / 二叉树的最大深度
java·数据结构·算法·leetcode
Miraitowa_cheems2 小时前
LeetCode算法日记 - Day 94: 最长的斐波那契子序列的长度
java·数据结构·算法·leetcode·深度优先·动态规划
ada7_3 小时前
LeetCode(python)——49.字母异位词分组
java·python·leetcode
L_09073 小时前
【Algorithm】Day-11
c++·算法·leetcode
一匹电信狗5 小时前
【C++】哈希表详解(开放定址法+哈希桶)
服务器·c++·leetcode·小程序·stl·哈希算法·散列表
nju_spy6 小时前
力扣每日一题(四)线段树 + 树状数组 + 差分
数据结构·python·算法·leetcode·面试·线段树·笔试
冰糖拌面6 小时前
GO写的http服务,清空cookie
服务器·http·golang