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
}
相关推荐
pursuit_csdn42 分钟前
LeetCode 1022. Sum of Root To Leaf Binary Numbers
算法·leetcode·深度优先
踩坑记录2 小时前
leetcode hot100 35. 搜索插入位置 medium 二分查找
leetcode
普通网友4 小时前
PHP语言的正则表达式
开发语言·后端·golang
-海绵东东-5 小时前
哈希表······················
算法·leetcode·散列表
菜鸡儿齐6 小时前
leetcode-全排列
算法·leetcode·深度优先
不想看见4046 小时前
Maximal Square 基本动态规划:二维--力扣101算法题解笔记
算法·leetcode·动态规划
夏乌_Wx6 小时前
LeetCode 160. 相交链表 | 三种解法吃透核心逻辑(哈希表 + 双指针 + 长度对齐)
leetcode·链表·哈希表
Hag_206 小时前
LeetCode Hot100 53.最大子数组和
数据结构·算法·leetcode
pursuit_csdn6 小时前
LeetCode 1461. Check If a String Contains All Binary Codes of Size K
算法·leetcode·职场和发展
Crazy________7 小时前
力扣113个mysql简单题解析(包含plus题目)
mysql·算法·leetcode·职场和发展