Is this constant memory?


  • 0
    D

    it seems to be O(n) time and memory..

    int firstMissingPositive(int* nums, int numsSize) {
        int i=0 ;
        char *f = malloc(numsSize+1);
        bzero(f, numsSize+1);
        for (i=0;i<numsSize;i++)
        {
            if (nums[i]>0 && nums[i]<=numsSize)f[nums[i]]=1;
        }
        for (i=1;i<=numsSize;i++)
            if (f[i] == 0) break ;
        free(f) ;
        return i ;
    
    }

  • 1

    Obviously it isn't. How did you forget that you use malloc(numsSize+1)?


Log in to reply
 

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