[プログラマー]H-Index
4949 ワード
質問リンク:プログラマ-ソート>H-Index
プール1(py)
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
プール2(js)
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;
}
}
}
Reference
この問題について([プログラマー]H-Index), 我々は、より多くの情報をここで見つけました https://velog.io/@eunbani/프로그래머스-H-Indexテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol