My 0ms c solution ..


  • 0
    F
    int* grayCode(int n, int* returnSize) {
    *returnSize=1;
    int i;
    int temp=*returnSize;
    int over=0;
    int count=1;
    for(i=0;i<n;i++)
        *returnSize=(*returnSize)*2;
    int *res=(int *)malloc(sizeof(int) * (*returnSize));
    res[0]=0;
    while(over<n){
        for(i=temp;i>0;i--){
            res[count]=res[i-1]+(1<<over);    
            count++;
        }
        temp=temp*2;
        over++;
    }
    return res;
    

    }


Log in to reply
 

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