/** * 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
时间: 2024-10-19 16:39:13