반응형
숫자로 이뤄진 벡터내에 각 벡터값보다 작은 값의 갯수를 반환하는 문제.
역시 이중 for문을 통해 해결했다.
class Solution {
public:
vector<int> smallerNumbersThanCurrent(vector<int>& nums) {
vector<int>ans;
int cnt = 0;
for(int i=0; i<nums.size();i++){
cnt = 0;
for(int j=0; j<nums.size();j++)
if(nums[i]>nums[j])
cnt++;
ans.push_back(cnt);
}
return ans;
}
};
반응형
'IT > 알고리즘' 카테고리의 다른 글
9] Leetcode 1281. Subtract the Product and Sum of Digits of an Integer (0) | 2020.06.22 |
---|---|
8] Leetcode 1313. Decompress Run-Length Encoded List (0) | 2020.06.21 |
6] Leetcode 771. Jewels and Stones (0) | 2020.06.21 |
5] Leetcode 1342. Number of Steps to Reduce a Number to Zero (0) | 2020.06.21 |
4] Leetcode 1108. Defanging an IP Address (0) | 2020.06.21 |
댓글