leetcode 2和c leetcode-日常记录准备每天不leetcode这个leetcode并用markdown文档做个简单的记录。简单的2021-06-03星期四1365.比当前数小的数有多少。
C++:
class Solution {
public:
vector<int> smallerNumbersThanCurrent(vector<int>& nums) {
vector<int> res;
for (int i = 0; i < nums.size(); i++)
res.push_back(compare_nums(nums, nums[i]));
return res;
}
int compare_nums(vector<int>& nums, int temp) {
int res = 0;
for (int i = 0; i < nums.size(); i++)
if (nums[i] < temp)
res++;
return res;
}
};
</int></int></int></int>
Python :
class Solution:
def smallerNumbersThanCurrent(self, nums):
return [sum(j < i for j in nums) for i in nums]
暂无评论