Why error"time limit exceed" appears?


  • 0
    B
    int removeDuplicates(vector<int>& nums) {
        if(nums.empty()) return 0;
        if(nums.size()==1) return 1;
        int length=nums.size();
        auto end=nums.end()-1;
        auto itr=nums.begin();
        while(itr!=end){
            if(*itr==*(itr+1)){
                for(auto i=itr+1;i!=end;i++){
                    *i=*(i+1);
                }
                *end=*itr;
                end--;
                length--;
            }
            else{
                itr++;
            }
        }
        return length;
    }

  • 1
    E

    obviously, your code runs too slow.


Log in to reply
 

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