My accepted concise C code


  • -4
    C

    int firstMissingPositive(int A[], int n) {
    int HIT = -199928;
    for(int i=0;i<n; i++){
    int t = A[i];
    while(t!=HIT && t>=1 && t<=n){
    int temp = A[t-1];
    A[t-1] = HIT;
    t = temp;
    }
    }
    for(int i=0; i<n; i++){
    if(A[i]!=HIT){
    return i+1;
    }
    }
    return n+1;
    }


Log in to reply
 

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