| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 캐나다 영주권
- 방통대
- 조지아텍
- cpp
- mpnp
- 코딩테스트
- 온라인석사
- omscs
- Plotting
- C++
- EOI
- 위니펙
- leetcode
- 알고리즘
- 프로그래머스
- 선형대수
- machine learning
- MATLAB
- LAA
- zeros
- 컴퓨터과학과
- 개발자
- 기본
- 주정부이민
- 딥러닝
- LV1
- 방송통신대학교
- Deep learning
- 머신러닝
- 매트랩
Archives
- Today
- Total
Byte by Byte
leetcode) 1282. Group the People Given the Group Size They Belong To c++ 본문
개발 로그/알고리즘
leetcode) 1282. Group the People Given the Group Size They Belong To c++
CyberSoak 2021. 9. 21. 15:03🔑 3가지 주안점.
//map에 데이터 넣을때
m.insert(pair<int,int>(groupSizes[i],i));
//key find했을 때, 아무것도 없으면, m.end()를 return한다.
if(m.find(i)!=m.end()){
//m.equal_range(i).first ~ m.equal_range(i).second : first에는 begin값, second에는 end값이 있다.
for (auto it= m.equal_range(i).first; it!=m.equal_range(i).second; ++it){
//it의 data를 return.
v.push_back(it->second);
👉 전체 코드 내용
class Solution {
public:
vector<vector<int>> groupThePeople(vector<int>& groupSizes) {
multimap<int,int> m;
vector<vector<int>>res;
for(int i =0; i< groupSizes.size();i++){
m.insert(pair<int,int>(groupSizes[i],i));
}
for (int i= 0 ; i <=groupSizes.size(); i++){
if(m.find(i)!=m.end()){
int tmpcnt=0;
vector<int>v;
for (auto it= m.equal_range(i).first; it!=m.equal_range(i).second; ++it){
v.push_back(it->second);
++tmpcnt;
if(tmpcnt==i){
res.push_back(v);
v.clear();
tmpcnt=0;
}
}
}
}
return res;
}
};'개발 로그 > 알고리즘' 카테고리의 다른 글
| leetcode) 938. Range Sum of BST c++ (0) | 2021.09.23 |
|---|---|
| Leetcode) 1315. Sum of Nodes with Even-Valued Grandparent c++ (0) | 2021.09.21 |
| leetcode) 807. Max Increase to Keep City Skyline c++ (0) | 2021.09.20 |
| leetcode) 1769. Minimum Number of Operations to Move All Balls to Each Box / C++ (0) | 2021.09.18 |
| Leetcode) 1816. Truncate Sentence c++ (0) | 2021.09.14 |