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