Golang | Leetcode Golang题解之第406题根据身高重建队列

题目:

题解:

Go 复制代码
func reconstructQueue(people [][]int) (ans [][]int) {
    sort.Slice(people, func(i, j int) bool {
        a, b := people[i], people[j]
        return a[0] > b[0] || a[0] == b[0] && a[1] < b[1]
    })
    for _, person := range people {
        idx := person[1]
        ans = append(ans[:idx], append([][]int{person}, ans[idx:]...)...)
    }
    return
}
相关推荐
And_Ii几秒前
LeetCode 026. 重排链表
算法·leetcode·链表
是娇娇公主~6 分钟前
力扣——146.LRU缓存详解
算法·leetcode·缓存
_深海凉_10 分钟前
LeetCode热题100-路径总和 III
算法·leetcode·职场和发展
XMYX-012 分钟前
35 - Go 文件操作:读写与临时文件
golang
YL2004042620 分钟前
054实现Trie(前缀树)
数据结构·leetcode
姚不倒24 分钟前
Go语言实战:多态文件存储系统(接口、错误处理、panic/recover)
云原生·golang
Achou.Wang1 小时前
Docker 多阶段构建:优化 Go 应用镜像大小的最佳实践
elasticsearch·docker·golang
进击的荆棘1 小时前
优选算法——哈希表
c++·算法·leetcode·哈希算法·散列表
khalil10201 小时前
代码随想录算法训练营Day-55 图论06 | 108.冗余连接、109.冗余连接II
c++·算法·leetcode·图论·并查集
进击的荆棘1 小时前
优选算法——字符串
开发语言·c++·算法·leetcode·字符串