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
}
相关推荐
Wang's Blog17 小时前
Go-Zero 项目开发47:自研微服务框架的必要性与核心结构设计
开发语言·微服务·golang
普通攻击往后拉18 小时前
Leetcode 206. 反转链表
算法·leetcode·链表
名字还没想好☜1 天前
Go 用 bufio.Scanner 读大文件踩坑:默认 64KB 行上限、Buffer 扩容与按 Token 切分
开发语言·后端·golang·go
techdashen1 天前
Go设计取舍之六: sync.Mutex正常模式与饥饿模式
开发语言·后端·golang
橘子汽水1681 天前
Leetcode 230,98:二叉搜索树中第K小的元素,验证二叉搜索树
算法·leetcode·职场和发展
普通攻击往后拉1 天前
Leetcode 448. 找到所有数组中消失的数字
算法·leetcode·职场和发展
mifengxing1 天前
LeetCode 189 轮转数组|3种解法拆解,从暴力到O(1)原地最优解
数据结构·算法·leetcode
程序员-珍1 天前
力扣 877. 石子游戏
算法·leetcode·游戏
wabs6661 天前
关于链表【力扣19.删除链表的倒数第N个节点的思考】
数据结构·leetcode·链表
Rabitebla1 天前
C++ STL 之 set 详解:从底层红黑树到实际应用
开发语言·数据结构·c++·算法·leetcode