LC 1365. How Many Numbers Are Smaller Than the Current Number

Nilanjan Deb · April 6, 2020

This is my CPP solution.

class Solution {
public:
    vector<int> smallerNumbersThanCurrent(vector<int>& nums) {
        int n = nums.size();
        vector<int> ans;
        for(int i=0;i<n;i++){
            int cnt = 0;
            for(int j=0;j<n;j++){
                if(i!=j && nums[i]>nums[j])
                    cnt++;
            }
            ans.push_back(cnt);
        }
        return ans;
    }
};


Dicussion Forum