본문 바로가기

알고리즘

프로그래머스 42747번 | H-Index 문제 풀이 (Java)

문제

 

제출 코드

import java.util.Arrays;
import java.util.Collections;

public class Solution {
    public int solution(int[] citations) {
        int answer = 0;
        Integer[] array = Arrays.stream(citations).boxed().toArray(Integer[]::new);
        Arrays.sort(array, Collections.reverseOrder());
        for(int i = 0; i < array.length; i++) {
            if((i+1) > array[i]) {
             break;
            } else {
                answer++;
            }
        }
        return answer;
    }
}

 

 

문제 의도

- 자바정렬

- Stream

 

문제 출처