seunghyun Note
[프로그래머스] H-Index with JS 본문
728x90
반응형
링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42747
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제 풀이
문제가 진짜 한글이 더 어렵다 뭔 말이 이렇게 어렵냐...
코드는 매우 간단하다.
H-지수란 무엇인가?
정렬을 한 후에... index값과 크기 비교후 count를 하면 끝. 흐음.. H-지수... 내 이니셜과 비슷하니 꼭 기억할게.
다행히 간단한 정렬이라 버블팝, 셀렉션, insertion 넣었다.
정렬도 복습할겸... 다 사용해보기!!
function swap(arr, idx1, idx2) {
var temp = arr[idx1];
arr[idx1] = arr[idx2];
arr[idx2] = temp;
}
function insertionSort(arr) {
var currentVal;
for (var i = 1; i < arr.length; i++) {
currentVal = arr[i];
for (var j = i - 1; j >= 0 && arr[j] < currentVal; j--) {
arr[j + 1] = arr[j];
}
arr[j + 1] = currentVal;
}
return arr;
}
function bubbleSort(a){
for (let i = a.length; i > 0; i--) {
noSwaps = true;
for (let j = 0; j < i - 1; j++) {
if (a[j] <a[j + 1]) {
swap(a, j, j + 1);
noSwaps = false;
}
}
if (noSwaps) break;
}
}
function selectionSort(arr) {
for (let i = 0; i < arr.length; i++) {
var min = i;
for (let j = i + 1; j < arr.length; j++) {
if (arr[j] > arr[min]) {
min = j;
}
}
var temp = arr[i];
arr[i] = arr[min];
arr[min] = temp;
}
return arr;
}
function solution(citations) {
// bubbleSort(citations);
// insertionSort(citations);
// selectionSort(citations);
citations.sort((a,b)=>b-a);
console.log(citations);
let cnt= 0;
for (let i = 0; i < citations.length; i++) {
if (i < citations[i]) {
cnt++;
}
}
return cnt;
}
728x90
반응형
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] - 핸드폰 번호 가리기 with JS (0) | 2024.01.09 |
---|---|
[프로그래머스] - 가장 큰 수 with JS (0) | 2024.01.06 |
[프로그래머스] k번째수 with JS (0) | 2024.01.06 |
[프로그래머스] 피보나치 수 with JS (1) | 2024.01.06 |
[프로그래머스] 하샤드 수 with JS (0) | 2024.01.06 |