[프로그래머스, 42747] H-Index (java)
Problem Solving/Programmers

[프로그래머스, 42747] H-Index (java)

728x90

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

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

728x90

메모리: 83.6 MB, 시간: 0.33 ms

사용 알고리즘: 이분탐색

class Solution {
    public int solution(int[] citations) {
        
        int answer = 0;
        
        // 이분탐색
        int s = 0, e = 10_000, m;
        int count;
        while(s <= e) {
            
            m = (s + e) / 2;
            
            // m번 이상 인용된 논문 개수 세기
            count = 0;
            for(int c : citations) {
                if(c >= m) count++;
            }
            
            if(count >= m) {
                answer = m;
                s = m + 1;
            }
            else e = m - 1;
        }
    
        return answer;
    }
}
728x90