Get error: Time Limit Exceeded


  • 0
    C
    int majorityElement(int num[], int n) {
        void swap(int v[],int i,int j){
            int temp;
            temp = v[i];
            v[i] = v[j];
            v[j] = temp;
        }
        void quicksort(int v[],int left,int right){
            if(left>=right)
                return;
            swap(v,left,(left+right)/2);
            int last = left;
            for(int i = left+1; i<=right; i++)
                if(v[i]<v[left])
                    swap(v,i,++last);
            swap(v,left,last);
            quicksort(v,left,last-1);
            quicksort(v,last+1, right);
        }
        quicksort(num,0,n-1);
        return num[n/2];
    }
    

    get error: time limit exceeded when using quicksort. I sit and edit for an hour and still can't find the error....anybody help?


  • 0
    G

    I think it's because the Runtime is too long, not because there is an error.


Log in to reply
 

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