leetcode 1365 多少小于当前数字的数字

简介: leetcode 1365 多少小于当前数字的数字

多少小于当前数字的数字

暴力法

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

map法

class Solution {
public:
    vector<int> smallerNumbersThanCurrent(vector<int>& nums) {
        vector<int> result = nums;
        sort(result.begin() , result.end());
        map<int,int> my_map;
        for(int i=result.size()-1 ; i >= 0 ;i--)
            my_map[result[i]] = i;
        // for(auto it:my_map)
        //     cout<<it.first<<' '<<it.second<<endl; 
        for(int i=0 ; i<nums.size() ;i++)
        {
           result[i] = my_map[nums[i]];
        }
        return result;
    }
};
相关文章
|
17小时前
|
Go
golang力扣leetcode 713.乘积小于K的子数组
golang力扣leetcode 713.乘积小于K的子数组
19 0
|
17小时前
【力扣每日一题】1365. 有多少小于当前数字的数字
【力扣每日一题】1365. 有多少小于当前数字的数字
|
9月前
力扣 713. 乘积小于 K 的子数组
力扣 713. 乘积小于 K 的子数组
38 0
|
12月前
|
人工智能 搜索推荐 vr&ar
每日一题[LeetCode 315]计算右侧小于当前元素的个数
发现leetcode的困难难度做起来还是需要点时间的(还是我太菜了),而且可能大多数人也不能接受,所以明天开始穿插做中等难度题目。
|
12月前
力扣315计算右侧小于当前元素的个数
力扣315计算右侧小于当前元素的个数
67 0
LeetCode每日一题(17)—— 乘积小于 K 的子数组(双指针)
乘积小于 K 的子数组 1.题目 2.示例 3.思路 4.代码
|
算法 PHP
力扣(LeetCode)算法题解:1365. 有多少小于当前数字的数字
力扣(LeetCode)算法题解:1365. 有多少小于当前数字的数字
110 0
LeetCode Contest 178-1365. 有多少小于当前数字的数字 How Many Numbers Are Smaller Than the Current Number
LeetCode Contest 178-1365. 有多少小于当前数字的数字 How Many Numbers Are Smaller Than the Current Number
|
算法 C++ Python
双指针滑窗经典问题算法模板-附LeetCode每日一题题解:713. 乘积小于 K 的子数组-题解-python && C++源代码
双指针滑窗经典问题算法模板-附LeetCode每日一题题解:713. 乘积小于 K 的子数组-题解-python && C++源代码
LeetCode每日一题——713. 乘积小于 K 的子数组
给你一个整数数组 nums 和一个整数 k ,请你返回子数组内所有元素的乘积严格小于 k 的连续子数组的数目。
93 0

热门文章

最新文章