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
}
相关推荐
洛水水9 分钟前
【力扣100题】87.只出现一次的数字
数据结构·算法·leetcode
踏着七彩祥云的小丑23 分钟前
Go 学习第6天:结构体 + 切片 + range遍历
开发语言·学习·golang·go
风筝在晴天搁浅1 小时前
LeetCode CodeTop 82.删除排序链表中的重复元素Ⅱ
算法·leetcode·链表
洛水水1 小时前
【力扣100题】84.字符串解码
算法·leetcode·职场和发展
浮尘笔记1 小时前
Go实现大文件异步流式采集引擎
开发语言·后端·golang
洛水水2 小时前
【力扣100题】89.下一个排列
数据结构·算法·leetcode
洛水水2 小时前
【力扣100题】90.寻找重复数
算法·leetcode·职场和发展
alphaTao2 小时前
LeetCode 每日一题 2026/6/8-2026/6/14
算法·leetcode
l齐天2 小时前
Ubuntu 中编译 Go + PBC 程序为 Windows 11 可运行文件
windows·ubuntu·golang
jieyucx2 小时前
《Go 数据库编程开篇:彻底打通 database/sql 与 MySQL 驱动的连接池调优密码》
数据库·sql·golang