문제 링크 : 프로그래머스 - 정렬 > H-Index
def solution(citations):
answer = 0
citations.sort()
h = citations[-1]
idx = 0
while h >= 0:
for i in range(len(citations)):
if citations[i] >= h:
idx = i
break
if len(citations) - idx >= h and idx <= h:
return h
h -= 1
return answer
function solution(citations) {
var n = Math.max(...citations);
const LENGTH = citations.length;
for (let h = n; h >= 0; h--){
let cnt = citations.filter((citation) => citation >= h).length;
if (cnt >= h && LENGTH - cnt <= h){
return h;
}
}
}