티스토리 뷰

leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/

 

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

배열을 argument로 넘겨주면 해당 배열의 각 원소별로 배열 내 해당 원소보다 작은 원소가 있다면 count하여 각 count한 결과를 배열로 만들어서 return해주는 문제임.

class Solution {
public:
    vector<int> smallerNumbersThanCurrent(vector<int>& nums) {
        vector<int> re;
        for (int i = 0; i < nums.size(); i++) {
            int cnt = 0;
            for (int j = 0; j < nums.size(); j++) {
                if (i != j && nums[i] > nums[j]) cnt++;
            }
            re.push_back(cnt);
        }
        return re;
    }
};
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함