Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

코딩응급실

프로그래머스: H-index 본문

Java

프로그래머스: H-index

Daeryuk Kim 2024. 3. 7. 12:54
import java.util.*;

class Solution {
    public int solution(int[] citations) {
        
        Arrays.sort(citations);// 0 1 3 5 6
        
        int answer = 0;
        for (int i=0; i<citations.length; i++) {
            /*
            	과학자가 발표한 논문 5편 중, 3번 이상 인용된 논문이 
                3편 이상이므로 이 과학자의 H-Index는 3 입니다.
                
            	min: '0' = 0 5
                ans:  0 = 0 '0'
                
                min: '1' = 1 4
                ans: 1 = 0 '1'
                
                min: '3' = 3 3
                ans: 3 = 1 '3'
                
                min: '2' = 5 2
                ans: 3 = 3 '2'
                
                min: '1' = 6 1
                ans: 3 = 3 '1'
            */
            int min = Math.min(citations[i], citations.length - i);

            answer = Math.max(answer, min);
            
        }
                
        return answer;
    }
    
    public static void main(String[] args) {
        int[] citations = {3,0,6,1,5};
        
        Solution sol = new Solution();
        int result = sol.solution(citations);
        System.out.println(result); 
    }
}

'Java' 카테고리의 다른 글

프로그래머스: 의상  (0) 2024.03.07
프로그래머스: 행렬의 곱셈  (1) 2024.03.07
프로그래머스: n^2 배열 자르기  (0) 2024.03.07
프로그래머스: 카펫  (1) 2024.03.06
프로그래머스: 할인행사  (1) 2024.03.06