코테/프로그래머스

[프로그래머스/Lv. 2] H-Index

imname1am 2023. 4. 4. 00:33
반응형

🔺 문제

 

프로그래머스

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

programmers.co.kr

 

🔺 코드

import java.util.*;

class Solution {
    public int solution(int[] citations) {
        int answer = 0;      
        Arrays.sort(citations);
        
        for(int i = 0 ; i < citations.length ; i++) {
            int h = citations.length - i;   // 인용된 논문의 수
            
            if(citations[i] >= h) {
                answer = h;
                break;
            }
        }
    
        return answer;
    }
}
✅ 해결 아이디어
- 배열 정렬
- 논문 수를 감소시키면서 비교했을 때, (인용 횟수 >= 논문의 수)일 때의 논문의 수가 H-idx

악.... 코드만 보면 엄청 간단한데

머리가 안 돌아간다....

일찍 자야겠다...


🔺 다른 풀이들

 

프로그래머스

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

programmers.co.kr

import java.util.Arrays;

class Solution {
    public int solution(int[] citations) {
        int answer = 0;
        Arrays.sort(citations);
        for(int i=0; i<citations.length; i++){
            int smaller = Math.min(citations[i], citations.length-i);
            answer = Math.max(answer, smaller);
        }
        return answer;
    }
}

우째.. 이런 발상을...!!!!!

 


(참고)

 

[프로그래머스] H-Index - Java

https://programmers.co.kr/learn/courses/30/lessons/42747 코딩테스트 연습 - H-Index H-Index는 과학자의 생산성과 영향력을 나타내는 지표입니다. 어느 과학자의 H-Index를 나타내는 값인 h를 구하려고 합니다. 위키

hyojun.tistory.com

 

반응형