Leetcode每日一题:1365.how-many-numbers-are-smaller-than-the-current-number(有多少小于当前数字的数字)

在这里插入图片描述
思路:暴力破解的时间复杂度为O(n2),且这里数组长度不大于500,也就是上万的数量级,肯定不会超时;
在这里插入图片描述

class Solution {
    
    
public:
    vector<int> smallerNumbersThanCurrent(vector<int> &nums)
    {
    
    
        int len = nums.size();
        vector<int> res(len, 0);
        for (int i = 0; i < len; i++)
        {
    
    
            int temp = nums[i];
            int count = 0;
            for (int j = 0; j < len; j++)
            {
    
    
                if (nums[j] < temp)
                {
    
    
                    count++;
                }
            }
            res[i] = count;
        }
        return res;
    }
};

猜你喜欢

转载自blog.csdn.net/wyll19980812/article/details/109282957
今日推荐