[Programmers] H-Index(Lv.2)(C++)

Alice·2023년 8월 25일
0

풀이 소요시간 : 15분

기본 정렬문제다. lower_bound 메소드를 활용하면 쉽게 풀 수 있다.


전체 코드

#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int Ans = 0;

int solution(vector<int> citations) {
    sort(citations.begin(), citations.end());    
    while(true)
    {
        int element = 
            citations.end() - lower_bound(citations.begin(), citations.end(), Ans);
        
        if(element >= Ans)
        {
            Ans += 1;
            continue;
        }
        
        return Ans - 1;
    }
}
profile
SSAFY 11th

0개의 댓글