Posted on

Description

Submission

class Solution {
public:
    vector<int> smallerNumbersThanCurrent(vector<int>& nums) {
        int n = nums.size();
        vector<int> sorted(n);
        partial_sort_copy(nums.begin(), nums.end(), sorted.begin(), sorted.end());

        vector<int> ret;
        for(int n: nums) {
            ret.push_back(lower_bound(sorted.begin(), sorted.end(), n) - sorted.begin());
        }
        return ret;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *