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
}
相关推荐
liuyunshengsir1 小时前
golang 中 make 和 new 的区别?
开发语言·后端·golang
储悠然2 小时前
Pascal语言的区块链
开发语言·后端·golang
小美爱刷题2 小时前
力扣DAY40-45 | 热100 | 二叉树:直径、层次遍历、有序数组->二叉搜索树、验证二叉搜索树、二叉搜索树中第K小的元素、右视图
数据结构·算法·leetcode
熬夜造bug3 小时前
LeetCode Hot100 刷题笔记(2)—— 子串、普通数组、矩阵
笔记·leetcode·矩阵
lvchaoq4 小时前
图解力扣回溯及剪枝问题的模板应用
leetcode·深度优先·剪枝·回溯·递归
Swift社区4 小时前
LeetCode 252 会议室题全解析:Swift 实现 + 场景还原
算法·leetcode·swift
Spring-wind4 小时前
【golang】堆和栈的区别
开发语言·golang
emmmmXxxy4 小时前
leetcode刷题-单调栈
算法·leetcode·职场和发展
MiyamiKK575 小时前
leetcode_数组 189. 轮转数组
python·算法·leetcode·职场和发展
ErizJ5 小时前
Go 微服务框架 | 中间件
微服务·中间件·golang