zoukankan      html  css  js  c++  java
  • 【leetcode】56. 合并区间

    int cmp(const void*a, const void*b){
        return (*(int**)a)[0] > (*(int**)b)[0];
    }
    int** merge(int** intervals, int intervalsSize, int* intervalsColSize, int* returnSize, int** returnColumnSizes){
        int** arr = (int**)calloc(intervalsSize, sizeof(int*));
        *returnSize = 0;
        *returnColumnSizes = (int*)calloc(intervalsSize, sizeof(int));
        qsort(intervals, intervalsSize, sizeof(int*), cmp);
        for (int i = 0; i < intervalsSize; i++){
            if (i == intervalsSize - 1 || intervals[i][1] < intervals[i + 1][0]){
                arr[(*returnSize)] = (int*)calloc(2, sizeof(int*));
                arr[(*returnSize)][0] = intervals[i][0];
                arr[(*returnSize)][1] = intervals[i][1];
                (*returnColumnSizes)[(*returnSize)++] = 2;
            }
            else if (intervals[i][1] >= intervals[i + 1][0]){
                intervals[i + 1][0] = intervals[i][0];
                intervals[i + 1][1] = (intervals[i][1]>intervals[i + 1][1]) ? intervals[i][1] : intervals[i + 1][1];
            }
        }
        return arr;
    }
  • 相关阅读:
    C++虚函数表解析(转)
    学习网址
    css 段落文字换行问题
    移动端fixed兼容问题
    半数集1
    汇编寄存器
    设计模式概述
    Vector用法介绍
    汇编PC硬件基本特征
    android 反编译总结
  • 原文地址:https://www.cnblogs.com/ganxiang/p/14118336.html
Copyright © 2011-2022 走看看