C语言 | Leetcode C语言题解之第354题俄罗斯套娃信封问题

题目:

题解:

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

int maxEnvelopes(int** envelopes, int envelopesSize, int* envelopesColSize) {
    if (envelopesSize == 0) {
        return 0;
    }

    qsort(envelopes, envelopesSize, sizeof(int*), cmp);

    int n = envelopesSize;
    int f[n];
    for (int i = 0; i < n; i++) {
        f[i] = 1;
    }
    int ret = 1;
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < i; ++j) {
            if (envelopes[j][1] < envelopes[i][1]) {
                f[i] = fmax(f[i], f[j] + 1);
            }
        }
        ret = fmax(ret, f[i]);
    }
    return ret;
}
相关推荐
轩轶子1 小时前
【C-项目】网盘(一期,线程池版)
服务器·c语言
m0_631270401 小时前
高级c语言(五)
c语言·开发语言
2401_858286111 小时前
53.【C语言】 字符函数和字符串函数(strcmp函数)
c语言·开发语言
程序猿练习生2 小时前
C++速通LeetCode中等第5题-无重复字符的最长字串
开发语言·c++·leetcode
lib钱2 小时前
RO通讯数据包
c语言
MogulNemenis4 小时前
力扣150题——位运算
数据结构·算法·leetcode
Freestyle Coding5 小时前
使用rust自制操作系统内核
c语言·汇编·microsoft·rust·操作系统
标标大人7 小时前
c语言中的局部跳转以及全局跳转
android·c语言·开发语言
huanxiangcoco9 小时前
55. 跳跃游戏
python·leetcode
__AtYou__9 小时前
Golang | Leetcode Golang题解之第413题等差数列划分
leetcode·golang·题解