My C Solution stuck in the testcase [-6,10,184] and don't know why


  • 0
    U

    I have no idea why my solution stuck in this testcase [-6,10,184]. I thought there is only reset output I should pay attention to. And my reset output should be fine. About the shuffle output, it could be any permutation of the [-6,10,184]. Did I misunderstand anything?

    int* solutionShuffle(Solution* obj, int *returnSize) {
        *returnSize=obj->size;
        if(obj->size==0)
            return NULL;
        srand(time(NULL));
        for(int i=0;i<obj->size;i++){
            int r1 = rand()%obj->size;
            swap(obj->nums,i,r1);
        }
        return obj->nums;
    }
    

  • 0
    V

    srand() should be called only once per "Solution", calling it repeatedly does not give you a list of random numbers.


Log in to reply
 

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