1313. 解压缩编码列表

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

  

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