프로그래머스(Programmers)
정렬 > H-Index
cepiloth
2018. 9. 30. 18:49
반응형
https://programmers.co.kr/learn/courses/30/lessons/42747
1. 문제
3 0 6 1 5 -> 정렬을 한다. 6 5 3 1 0
step 1 - [6] 5 3 1 0 - h 1증가
step 2 - 6 [5] 3 1 0 - h 1증가
step 3 - 6 5 [3] 1 0 - h 1증가
step 4 - 6 5 3 [1] 0 - h 3 이고 4 번째 원소가 1 임으로 증가하지 못 한다.
step 5 - 6 5 3 1 [0] - h 3 이고 5 번째 원소가 0 임으로 증가하지 못 한다.
2. 알고리즘
키워드 - 정렬
3. 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <string> #include <vector> #include <algorithm> #include <functional> using namespace std; int solution(vector<int> citations) { sort(citations.begin(), citations.end(), greater<int>()); int h = 0; while (h < citations.size() && citations[h] >= h+1) { ++h; } return h; } | cs |
반응형