상세 컨텐츠

본문 제목

H-Index (정렬)

프로그래머스 코딩테스트 풀이

by 발발개발 2022. 7. 14. 14:35

본문

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

 

프로그래머스

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

programmers.co.kr

 

풀이

import java.util.*;

class Solution {
    public int solution(int[] citations) {
        int n = citations.length;

        Arrays.sort(citations);

        int answer = 0;

        for (int h = 1; h <= n; h++) {
            if (isH_Index(citations, h)) {
                answer = h;
            } else {
                break;
            }
        }

        return answer;
    }

    public boolean isH_Index(int[] arr, int h) {
        int cnt = arr.length;

        for (int num : arr) {
            if (num < h) {
                cnt--;
            } else {
                break;
            }
        }

        return cnt >= h;
    }
}

'프로그래머스 코딩테스트 풀이' 카테고리의 다른 글

큰 수 만들기 (탐욕법(Greedy))  (0) 2022.07.14
카펫 (완전탐색)  (0) 2022.07.14
다리를 지나는 트럭 (스택/큐)  (0) 2022.07.11
위장 (해시)  (0) 2022.07.11
2 x n 타일링 (연습문제)  (0) 2022.07.08

관련글 더보기

댓글 영역