Neo找了些硬件基础,看了两集
下午摸鱼加看了点王爽汇编,用了旧电脑
写了easy难度leetcode一小个下午,一直在找不输出的Bug.最后发现是平台需要回传*returnSize大小,外加头尾对换判断后需要++、--
2460. 对数组执行操作1 /** 2 * Note: The returned array must be malloced, assume caller calls free(). 3 */ 4 int* applyOperations(int* nums, int numsSize, int* returnSize){ 5 if(numsSize == 1 || numsSize == 0){ 6 return nums; 7 } 8 for(int i = 0; i < numsSize - 1; i++){ 9 if(nums[i] == nums[i + 1]){ 10 nums[i] *= 2; 11 nums[i + 1]=0; 12 } 13 } 14 int top = 0; 15 int bottom = numsSize - 1; 16 int a; 17 while(top < bottom){ 18 while(1){ 19 if(nums[top] != 0){ 20 top++; 21 }else{ 22 if(nums[bottom] == 0){ 23 bottom--; 24 } 25 } 26 if((nums[top] == 0)&&(nums[bottom] != 0)){ 27 break; 28 } 29 if (top >= bottom) { 30 break; 31 } 32 } 33 34 a = nums[top]; 35 nums[top] = nums[bottom]; 36 nums[bottom] = a; 37 top++; 38 bottom--; 39 } 40 *returnSize = numsSize; 41 return nums; 42 } 43 //但是改变了数字次序,没有“执行完所有操作后,将 0 全部移动到数组末尾”C_1
标签:numsSize,10,bottom,int,top,nums,++,Day From: https://www.cnblogs.com/IslandNeo/p/16878533.html