본문 바로가기
[알고리즘 + 자료구조]/[프로그래머스]

프로그래머스 H-index

by Hevton 2023. 8. 8.
반응형

추천수를 가장 많이 받은 풀이와 내 풀이가 같은데, 거기서의 추천과 감탄 댓글들을 보면 괜히 내가 기분이 좋아지네..

 

    // 사이즈는 5
    // 6 5 4 1 0
    // count++ 하면서, 뒤에서부터 갯수 세고 현재 원소의 값 얻고
    // count가 원소보다 커지면 stop

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int solution(vector<int> citations) {

    sort(citations.begin(), citations.end(), greater<>());
    
    int count = 0;
    
    for(auto x : citations) {
        
        if(count >= x)
            break;
        
        count++;
    }
    return count;
}
반응형