文章目录
0 效果
1 题目
2 思路
3 代码
C:
int* printNumbers(int n, int* returnSize){
int num = 1;
for(int i = 0;i < n;i++){
num *= 10;
}
int* p = (int*) malloc(sizeof (int) * num);
num--;
for(int i = 0;i <= num;i++){
*(p + i) = i + 1;
}
*returnSize = num;
return p;
}
C++:
class Solution {
public:
vector<int> smallerNumbersThanCurrent(vector<int>& nums) {
int hash[101];
memset(hash, 0, sizeof(hash));
for(int i = 0;i < nums.size(); i++){
hash[nums[i]]++;
}
for(int i = 1;i < 101; i++){
hash[i] += hash[i - 1];
}
vector<int> ans;
for(int i = 0;i < nums.size();i++){
ans.push_back(nums[i] != 0 ? hash[nums[i] - 1]:0);
}
return ans;
}
};