일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 주정부이민
- 알고리즘
- zeros
- 방통대
- 코딩테스트
- 딥러닝
- machine learning
- 기본
- 매트랩
- 프로그래머스
- MATLAB
- EOI
- 캐나다 영주권
- 개발자
- cpp
- omscs
- 조지아텍
- 위니펙
- 머신러닝
- 선형대수
- Plotting
- Deep learning
- C++
- LV1
- 컴퓨터과학과
- 방송통신대학교
- LAA
- mpnp
- leetcode
- 온라인석사
Archives
- Today
- Total
Byte by Byte
1636. Sort Array by Increasing Frequency.cpp 본문
🔑 " map sort by value "
🚩 sort lambda식 익숙해지기.


class Solution {
public:
vector<int> frequencySort(vector<int>& nums) {
vector<int>res;
map<int,int>m;
for(int i =0; i<nums.size(); i++){
m[nums[i]]++;
}
vector<pair<int,int>>v;
for(auto it : m){
v.push_back(make_pair(it.first,it.second));
// cout<< it.first << " " << it.second <<endl;
}
// cout<< endl;
sort(v.begin(), v.end(), [](pair<int,int>&a, pair<int,int>&b){
return a.second != b.second ? a.second < b.second : a.first > b.first;
});
for(auto it: v){
// cout<< it.first << " ";
for(int i =0; i< nums.size(); i++){
if(nums[i] == it.first) res.push_back(nums[i]);
}
}
return res;
}
};
'개발 로그 > 알고리즘' 카테고리의 다른 글
1700. Number of Students Unable to Eat Lunch.cpp (0) | 2021.11.21 |
---|---|
349. Intersection of Two Arrays.cpp (0) | 2021.11.20 |
1002. Find Common Characters.cpp (0) | 2021.11.19 |
1030. Matrix Cells in Distance Order.cpp (0) | 2021.11.19 |
821. Shortest Distance to a Character.cpp (0) | 2021.11.16 |