首页 > 其他 > 详细

1313. 解压缩编码列表 - c

时间:2020-02-03 09:28:32      阅读:115      评论:0      收藏:0      [点我收藏+]
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* decompressRLElist(int* nums, int numsSize, int* returnSize){
    if (nums == NULL)
        return NULL;
    *returnSize = 0;
    for (int i = 0; i < numsSize; i += 2)
        (*returnSize) += nums[i];
    int tempSize = (*returnSize);
    //printf("%d", tempSize);
    int *res = malloc(sizeof(int) * tempSize);
    int resIndex = 0;
    for (int i = 0; i < numsSize; i += 2) {
        for (int j = 0; j < nums[i]; j++) {
            res[resIndex] = nums[i + 1];
            resIndex ++;
        }
    }
    return res;
}

  

1313. 解压缩编码列表 - c

原文:https://www.cnblogs.com/luckygxf/p/12254444.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!