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)
}
相关推荐
大胆飞猪15 小时前
递归、剪枝、回溯算法---全排列、子集问题(力扣.46,78)
算法·leetcode·剪枝
Swift社区18 小时前
LeetCode 421 - 数组中两个数的最大异或值
算法·leetcode·职场和发展
Kuo-Teng1 天前
LeetCode 206: Reverse Linked List
java·算法·leetcode·职场和发展
做怪小疯子1 天前
LeetCode 热题 100——哈希——最长连续序列
算法·leetcode·哈希算法
Dream it possible!1 天前
LeetCode 面试经典 150_二叉树_二叉树展开为链表(74_114_C++_中等)
c++·leetcode·链表·面试·二叉树
做怪小疯子1 天前
LeetCode 热题 100——双指针——三数之和
算法·leetcode·职场和发展
sin_hielo1 天前
leetcode 2536
数据结构·算法·leetcode
flashlight_hi1 天前
LeetCode 分类刷题:203. 移除链表元素
算法·leetcode·链表
py有趣1 天前
LeetCode算法学习之数组中的第K个最大元素
学习·算法·leetcode
吗~喽1 天前
【LeetCode】将 x 减到 0 的最小操作数
算法·leetcode