Insert sort method C++ use 68ms solution


  • 8
    J
     vector<int> countSmaller(vector<int>& nums) {
        int size = nums.size();
        vector<int> res;
        vector<int> temp;
        for(int i=size-1;i>=0;--i){
            res.push_back(insert(temp,nums[i]));
        }
        reverse(res.begin(),res.end());
        return res; 
    }
    int insert(vector<int>& temp,int num){
        int size = temp.size();
        int res=distance(temp.begin(),lower_bound(temp.begin(),temp.end(),num));
        temp.insert(temp.begin()+res,num);
        return res;
        
    }

  • 2
    L

    You are so familiar with C++ functions, cool


  • 0
    E

    This solution does not work. It got TLE.


Log in to reply
 

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