devlog_owen
[프로그래머스] H-Index 본문
728x90
문제
왜 이런걸 지표로 설정하신거죠?
나의 풀이
function solution(citations) {
let cita = citations.sort((a,b) => b-a)
for(let i=0; i<cita.length; i++){
let filteredCita = cita.filter(number => number >= i)
if(cita[i] === filteredCita.length){
return i+1
}
}
}
실패작이다. 왜 그런지 사실 잘 모르겠다.
function solution(citations) {
citations.sort((a, b) => b - a); // citations 배열을 내림차순으로 정렬
let hIndex = 0; // 초기 h-index 값을 0으로 설정
while (hIndex < citations.length && citations[hIndex] > hIndex) {
hIndex++; // hIndex < citations.length: 범위설정, citations[hIndex] 값과 hIndex를 비교하여 h-index를 찾음
}
return hIndex;
}
다시 풀어서 좀 더 깔끔하게 바꿈.
다른 사람 풀이
본문1
회고
본문1
728x90
'algorithm > (js)프로그래머스' 카테고리의 다른 글
[프로그래머스] 명예의 전당(1) (1) | 2023.12.04 |
---|---|
[프로그래머스] 콜라문제 (1) | 2023.12.01 |
[프로그래머스] K번째 수 (0) | 2023.11.17 |
[프로그래머스] 귤 고르기 (0) | 2023.11.16 |
[프로그래머스] 두 개 뽑아서 더하기 (1) | 2023.11.15 |