1470. 重新排列数组 - 力扣(LeetCode) (leetcode-cn.com)
int* shuffle(int* nums, intnumsSize, intn, int* returnSize){ inti = 0; int* ret = (int*)malloc(sizeof(int) * numsSize); for(i = 0;i < numsSize;i++) { if(i&1) ret[i] = nums[n + i / 2]; elseret[i] = nums[(i + 1)/2]; } *returnSize = numsSize; returnret; }
1929. 数组串联 - 力扣(LeetCode) (leetcode-cn.com)
int* getConcatenation(int* nums, intnumsSize, int* returnSize){ inti = 0; int* ret = (int*)malloc(sizeof(int) * numsSize * 2); for(i = 0;i < numsSize;i++) { ret[i +numsSize] = ret[i] = nums[i]; } *returnSize = 2 * numsSize; returnret; }
1920. 基于排列构建数组 - 力扣(LeetCode) (leetcode-cn.com)
1920. 基于排列构建数组 - 力扣(LeetCode) (leetcode-cn.com)
int* buildArray(int* nums, intnumsSize, int* returnSize){ inti = 0; int* ret = (int*)malloc(sizeof(int) * numsSize); for(i = 0;i < numsSize;i++) { ret[i] = nums[nums[i]]; } *returnSize = numsSize; returnret; }
1480. 一维数组的动态和 - 力扣(LeetCode) (leetcode-cn.com)
1480. 一维数组的动态和 - 力扣(LeetCode) (leetcode-cn.com)
int* runningSum(int* nums, intnumsSize, int* returnSize){ inti = 0; int* ret = (int*)malloc(sizeof(int) * numsSize); for(i = 0;i < numsSize;i++) { intj = i; intsum = 0; for(j = 0;j <= i;j++) { sum += nums[j]; } ret[i] = sum; } *returnSize = numsSize; returnret; }
剑指 Offer 58 - II. 左旋转字符串 - 力扣(LeetCode) (leetcode-cn.com)
char* reverseLeftWords(char* s, intk){ inti; intn = strlen(s); char *ret = (char *)malloc( (n + 1) * sizeof(char) ); // (1) for(i = 0; i < n; ++i) { ret[i] = s[(i + k) % n]; // (2) } ret[n] = '\0'; // (3) returnret; }
1108. IP 地址无效化 - 力扣(LeetCode) (leetcode-cn.com)
char * defangIPaddr(char * address){ char* ret = (char*)malloc(1000 * sizeof(char)); intreturnSize = 0; inti = 0; for(i = 0;address[i];i++) { if(address[i] == '.') { ret[ returnSize++] = '['; ret[ returnSize++] = '.'; ret[ returnSize++] = ']'; } elseret[returnSize++] = address[i]; } ret[returnSize] = '\0'; returnret; }
Loading Question... - 力扣(LeetCode) (leetcode-cn.com)
char* replaceSpace(char* s){ char* ret = (char*)malloc(300001 * sizeof(char)); intreturnSize = 0; inti = 0; for(i = 0;s[i];i++) { if(s[i] == ' ') { ret[returnSize ++] = '%%'; ret[returnSize ++] = '2'; ret[returnSize ++] = '0'; } elseret[returnSize ++] = s[i]; } ret[ returnSize] ='\0'; returnret; }
1365. 有多少小于当前数字的数字 - 力扣(LeetCode) (leetcode-cn.com)
int* smallerNumbersThanCurrent(int* nums, intnumsSize, int* returnSize){ inti = 0; int* ret = (int*)malloc(numsSize * sizeof(int)); for(i = 0;i < numsSize;i++) { intcount = 0; for(intj = 0;j < numsSize;j++) { if(nums[i] > nums[j]) count++; } ret[i] = count; } *returnSize = numsSize; returnret; }
1389. 按既定顺序创建目标数组 - 力扣(LeetCode) (leetcode-cn.com)
int* createTargetArray(int* nums, intnumsSize, int* index, intindexSize, int* returnSize){ intlen = 0; inti,j,ins,idx; int* ret = (int*)malloc(sizeof(int) * numsSize); for(i = 0;i < numsSize;i++) { idx = index[i]; ins = nums[i]; for(j = len;j > idx;--j) { ret[j] = ret[j-1]; } ret[idx] = ins; ++len; } *returnSize = len; returnret; }