当前位置: 首页 > news >正文

C语言 | Leetcode C语言题解之第406题根据身高重建队列

题目:

题解:

int cmp(const void* _a, const void* _b) {int *a = *(int**)_a, *b = *(int**)_b;return a[0] == b[0] ? a[1] - b[1] : b[0] - a[0];
}int** reconstructQueue(int** people, int peopleSize, int* peopleColSize, int* returnSize, int** returnColumnSizes) {qsort(people, peopleSize, sizeof(int*), cmp);int** ans = malloc(sizeof(int*) * peopleSize);*returnSize = 0;*returnColumnSizes = malloc(sizeof(int) * peopleSize);for (int i = 0; i < peopleSize; i++) {(*returnColumnSizes)[i] = 2;}for (int i = 0; i < peopleSize; ++i) {int* person = people[i];(*returnSize)++;for (int j = (*returnSize) - 1; j > person[1]; j--) {ans[j] = ans[j - 1];}int* tmp = malloc(sizeof(int) * 2);tmp[0] = person[0], tmp[1] = person[1];ans[person[1]] = tmp;}return ans;
}
http://www.lryc.cn/news/439158.html

相关文章:

  • 【Git】初识Git
  • vue3 透传 Attributes
  • 4.接口测试基础(Jmter工具/场景二:一个项目由多个人负责接口测试,我只负责其中三个模块,协同)
  • electron react离线使用monaco-editor
  • Python 的 WSGI 简单了解
  • 基于stm32使用ucgui+GUIBuilder开发ui实例
  • Spring扩展点系列-ApplicationContextAwareProcessor
  • 基于Keil软件实现实时时钟(江协科技HAL库)
  • dedecms靶场(四种webshell姿势)
  • PHP:强大的Web开发语言
  • 06_Python数据类型_元组
  • 【Vue】- ref获取DOM元素和购物车案例分析
  • 【AI大模型】ChatGPT模型原理介绍(下)
  • Python数据分析与可视化实战指南
  • react18基础教程系列-- 框架基础理论知识mvc/jsx/createRoot
  • 牛客周赛 Round 60 折返跑(组合数学)
  • 深入浅出Java匿名内部类:用法详解与实例演示
  • 数据库MySQL、Mariadb、PostgreSQL、MangoDB、Memcached和Redis详细介绍
  • 【ArcGIS Pro实操第七期】栅格数据合并、裁剪及统计:以全球不透水面积为例
  • 【Linux】Image、zImage与uImage的区别
  • 算子加速(3):自定义cuda扩展
  • 信息安全数学基础(14)欧拉函数
  • 7-17 汉诺塔的非递归实现
  • word文档无损原样转pdf在windows平台使用python调用win32com使用pip安装pywin32
  • 海康威视相机在QTcreate上的使用教程
  • 进程状态、进程创建和进程分类
  • java后端请求调用三方接口
  • C#使用TCP-S7协议读写西门子PLC(三)
  • 铝型材及其常用紧固件、连接件介绍
  • 【裸机装机系列】7.kali(ubuntu)-安装开发所需工具