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)
}
相关推荐
Fly Wine3 小时前
Leetcode之有效字母异位词
算法·leetcode·职场和发展
lars_lhuan3 小时前
Go WaitGroup 源码解析
golang
程序员夏末4 小时前
【LeetCode | 第七篇】算法笔记
笔记·算法·leetcode
hanlin037 小时前
刷题笔记:力扣第43、67题(字符串计算)
笔记·算法·leetcode
人间打气筒(Ada)8 小时前
如何基于 Go-kit 开发 Web 应用:从接口层到业务层再到数据层
开发语言·后端·golang
We་ct10 小时前
LeetCode 34. 在排序数组中查找元素的第一个和最后一个位置:二分查找实战
前端·算法·leetcode·typescript·二分
ccLianLian11 小时前
leetcode-hot100
算法·leetcode·职场和发展
nainaire11 小时前
速通LeetCode hot100——(1~9 哈希,双指针,滑动窗口)
c++·笔记·算法·leetcode
XiYang-DING12 小时前
【LeetCode】LCR 019. 验证回文串 II
算法·leetcode·职场和发展
灰色小旋风12 小时前
力扣18 四数之和(C++)
数据结构·算法·leetcode