본문 바로가기

코딩테스트/프로그래머스

[프로그래머스 - Level2] H-Index / 2022.07.14

 

https://school.programmers.co.kr/learn/courses/30/lessons/42747

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

import java.util.*;
class Solution {
    public int solution(int[] citations) {
        Arrays.sort(citations);
        // 0 1 3 5 6
        for(int i=0; i<citations.length; i++){
            int h = citations[i]; // h는 인용 횟수
            int up = citations.length - i; // h회 이상 인용된 논문의 개수
            if(h >= up){ // 인용 횟수가 h회 이상 인용된 논문의 개수보다 크거나 같을 때
                return up; // 그것이 최대값
            }
        }
        return 0;
    }
}