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
}
相关推荐
女王大人万岁1 小时前
Go标准库 io与os库详解
服务器·开发语言·后端·golang
TracyCoder1231 小时前
LeetCode Hot100(13/100)——238. 除了自身以外数组的乘积
算法·leetcode
Anastasiozzzz1 小时前
LeetCode Hot100 215. 数组中的第K个最大元素
数据结构·算法·leetcode
让我上个超影吧1 小时前
【力扣76】最小覆盖子串
算法·leetcode·职场和发展
求梦8203 小时前
【力扣hot100题】合并两个有序链表(22)
算法·leetcode·链表
女王大人万岁3 小时前
Go语言time库核心用法与实战避坑
服务器·开发语言·后端·golang
踩坑记录3 小时前
leetcode hot100 21.合并两个有序链表 链表 easy
leetcode
IT_Octopus3 小时前
力扣热题100 20. 有效的括号
算法·leetcode
木井巳3 小时前
【递归算法】求根节点到叶节点数字之和
java·算法·leetcode·深度优先
想进个大厂3 小时前
代码随想录day29 贪心03
算法·leetcode·职场和发展