Is it a compiler bug?


  • 0
    A

    Here is my code,

    int removeDuplicates(int* nums, int numsSize) {
    
    
    if (numsSize <= 1) {return numsSize;}
    
    int compared_pointa= 0;
    int compared_pointb = 1;
    int change_point= 1;
    
    while(compared_pointb < numsSize) {
        if((nums[compared_pointa] == nums[compared_pointb]) &&
           (change_point - compared_pointa == 1)) {
                change_point++;
        } else if (nums[compared_pointa] != nums[compared_pointb]) {
                nums[change_point] = nums[compared_pointb];
                compared_pointa = change_point;
                change_point++;
        }
        compared_pointb++;
    }
    
    nums = (int*)realloc(nums, (change_point+1)*sizeof(int));
    
    return change_point;
    
    }
    

    The submission result keeps showing that there is runtime error on my code. The last executed input is
    [1,1,2,2,3,3,4,4]. But when I tried this input, my answer and the expected answer is totally the same (both are [1,1,2,2,3,3,4,4]). I am wondering it is my fault or just a complier bug?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.