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
}
相关推荐
赴前尘17 分钟前
golang获取一个系统中没有被占用的端口
开发语言·后端·golang
sandyznb29 分钟前
go面试汇总
开发语言·面试·golang
im_AMBER1 小时前
Leetcode 85 【滑动窗口(不定长)】最多 K 个重复元素的最长子数组
c++·笔记·学习·算法·leetcode·哈希算法
2401_841495642 小时前
【LeetCode刷题】跳跃游戏Ⅱ
数据结构·python·算法·leetcode·数组·贪心策略·跳跃游戏
rannn_1113 小时前
【SQL题解】力扣高频 SQL 50题|DAY5
数据库·后端·sql·leetcode·题解
ChineHe4 小时前
Gin框架基础篇004_中间件的使用与机制详解
后端·golang·gin
LYFlied4 小时前
【每日算法】LeetCode 279. 完全平方数(动态规划)
前端·算法·leetcode·面试·动态规划
serendipity_hky4 小时前
【go语言 | 第6篇】Go Modules 依赖解决
开发语言·后端·golang
努力学算法的蒟蒻4 小时前
day43(12.24)——leetcode面试经典150
算法·leetcode·面试
吴佳浩 Alben4 小时前
Go 1.25.5 通关讲解
开发语言·后端·golang