1313. 解压缩编码列表 - c

/**
 * 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;
}

  

posted on 2020-02-03 00:55  luckygxf  阅读(193)  评论(0编辑  收藏  举报

导航