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
}
相关推荐
flashlight_hi20 小时前
LeetCode 分类刷题:199. 二叉树的右视图
javascript·算法·leetcode
LYFlied20 小时前
【每日算法】LeetCode 46. 全排列
前端·算法·leetcode·面试·职场和发展
小信啊啊21 小时前
Go语言数组与切片的区别
开发语言·后端·golang
云霄IT1 天前
docker使用教程之部署第一个go项目
docker·容器·golang
LYFlied1 天前
【每日算法】131. 分割回文串
前端·数据结构·算法·leetcode·面试·职场和发展
长安er1 天前
LeetCode 300/152/416/32 动态规划进阶题型总结(最长递增子序列→最长有效括号)
数据结构·算法·leetcode·动态规划·剪枝
季远迩1 天前
LeetCode 热题 100 Python3易懂题解(更新中)
算法·leetcode·哈希算法
Tony Bai1 天前
Go 1.26 新特性前瞻:从 Green Tea GC 到语法糖 new(expr),性能与体验的双重进化
开发语言·后端·golang
Dream it possible!1 天前
LeetCode 面试经典 150_回溯_组合(99_77_C++_中等)
c++·leetcode·面试·回溯
好易学·数据结构1 天前
可视化图解算法74:最小花费爬楼梯
数据结构·算法·leetcode·动态规划·力扣