본문 바로가기
IT/알고리즘

7] Leetcode 1365. How Many Numbers Are Smaller Than the Current Number

by 깻잎쌈 2020. 6. 21.
반응형

숫자로 이뤄진 벡터내에 각 벡터값보다 작은 값의 갯수를 반환하는 문제.

 

How Many Numbers Are Smaller Than the Current Number - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

역시 이중 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; 
    }
};
반응형

댓글