C语言 | Leetcode C语言题解之第452题用最少数量的箭引爆气球

题目:

题解:

cpp 复制代码
int cmp(void* _a, void* _b) {
    int *a = *(int**)_a, *b = *(int**)_b;
    return a[1] < b[1] ? -1 : 1;
}

int findMinArrowShots(int** points, int pointsSize, int* pointsColSize) {
    if (!pointsSize) {
        return 0;
    }
    qsort(points, pointsSize, sizeof(int*), cmp);
    int pos = points[0][1];
    int ans = 1;
    for (int i = 0; i < pointsSize; ++i) {
        if (points[i][0] > pos) {
            pos = points[i][1];
            ++ans;
        }
    }
    return ans;
}
相关推荐
程序员与背包客_CoderZ21 小时前
Linux D-Bus通信协议详解:从入门到C/C++编码实战
linux·服务器·c语言·c++·嵌入式硬件·嵌入式软件·dbus
嵌入式阿蔡1 天前
HAL库 vs LL库 vs 寄存器:到底用哪个?
c语言·stm32·单片机·嵌入式硬件·嵌入式实时数据库
evans在进步1 天前
LeetCode 394:字符串解码——Java 单栈模拟与嵌套解析详解
java·python·leetcode
Yyyyyy~1 天前
【C】C语言常见概念
c语言
Nil2081 天前
leetcode 189轮转数组
数据结构·算法·leetcode
吃着火锅x唱着歌1 天前
LeetCode 3885.设计事件管理器
算法·leetcode·职场和发展
土司大王1 天前
LeetCode hto100——字母异位词分组
java·算法·leetcode
嵌入式阿蔡1 天前
CAN总线入门:从协议帧到STM32实战
c语言·stm32·单片机·嵌入式硬件·嵌入式实时数据库
LONGZETECH1 天前
无人机组装调试实训高损耗痛点分析与虚拟仿真教学落地方案
c语言·开发语言·架构·无人机
土司大王1 天前
LeetCode hot100——两数之和
数据结构·算法·leetcode