프로그래머스/LEVEL 2

H-Index

GenieLove! 2021. 4. 17. 17:02
728x90
반응형

Java

import java.util.*;
class Solution {
    public int solution(int[] citations) {
        int answer = 0;
        int[] count = new int[citations.length + 1];
        
        for(int i = 0; i < citations.length; i++){
            for(int j = 1; j <= citations[i] && j < count.length; j++){
                count[j]++;
            }
        }
        
        for(int i = count.length - 1; i > 0; i--){
            if(count[i] >= i)
                return i;
        }
        
        return answer;
    }
}

Python

def solution(citations):
    citations.sort(reverse=True)
    answer = max(map(min, enumerate(citations, start=1)))#enumerate공부
    return answer
    
#     내풀이
#     countList = [0 for i in range(len(citations) + 1)]
    
#     for i in range(0, len(citations)):
#         for j in range(1, (citations[i] + 1)):
#             if j < len(countList):
#                 countList[j] += 1
    
#     for i in range(len(countList) - 1, 0, -1):
#         if i <= countList[i]:
#             return i
    
#     return 0
728x90
반응형

'프로그래머스 > LEVEL 2' 카테고리의 다른 글

위장  (0) 2021.04.24
구명보트  (0) 2021.04.24
전화번호 목록  (0) 2021.04.17
조이스틱  (0) 2021.04.14
큰 수 만들기  (0) 2021.04.14