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)
}
相关推荐
夏鹏今天学习了吗16 小时前
【LeetCode热题100(83/100)】最长递增子序列
算法·leetcode·职场和发展
AlenTech17 小时前
155. 最小栈 - 力扣(LeetCode)
算法·leetcode·职场和发展
坚持不懈的大白19 小时前
Leetcode学习笔记
笔记·学习·leetcode
Tisfy20 小时前
LeetCode 3047.求交集区域内的最大正方形面积:2层循环暴力枚举
算法·leetcode·题解·模拟·枚举·几何
栈与堆21 小时前
LeetCode 21 - 合并两个有序链表
java·数据结构·python·算法·leetcode·链表·rust
鹿角片ljp1 天前
力扣7.整数反转-从基础到边界条件
算法·leetcode·职场和发展
java修仙传1 天前
力扣hot100:前K个高频元素
算法·leetcode·职场和发展
爱编码的傅同学1 天前
【今日算法】Leetcode 581.最短无序连续子数组 和 42.接雨水
数据结构·算法·leetcode
YuTaoShao1 天前
【LeetCode 每日一题】2053. 数组中第 K 个独一无二的字符串
算法·leetcode·职场和发展
毅炼1 天前
hot100打卡——day09
java·leetcode