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
}
相关推荐
Kuo-Teng1 小时前
LeetCode 160: Intersection of Two Linked Lists
java·算法·leetcode·职场和发展
码上淘金3 小时前
在 YAML 中如何将 JSON 对象作为字符串整体赋值?——兼谈 Go Template 中的 fromJson 使用
java·golang·json
橘颂TA4 小时前
【剑斩OFFER】算法的暴力美学——点名
数据结构·算法·leetcode·c/c++
愚润求学7 小时前
【动态规划】专题完结,题单汇总
算法·leetcode·动态规划
·白小白9 小时前
力扣(LeetCode) ——43.字符串相乘(C++)
c++·leetcode
小生凡一9 小时前
图解|Go语言实现 Agent|LLM+MCP+RAG
开发语言·后端·golang
pipip.11 小时前
Go原生高性能内存网关IMS,比Redis更快
开发语言·redis·golang
一匹电信狗13 小时前
【C++11】Lambda表达式+新的类功能
服务器·c++·算法·leetcode·小程序·stl·visual studio
在等晚安么13 小时前
力扣面试150题打卡
算法·leetcode·面试
q***062913 小时前
环境安装与配置:全面了解 Go 语言的安装与设置
开发语言·后端·golang