Skip to content

Commit 723fe22

Browse files
authored
Merge pull request #833 from khw970421/master
[야근 지수]
2 parents 89cae7e + 750030e commit 723fe22

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

programmers/난이도별/level02.H-Index/khw970421.js

+13-15
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
function solution(citations) {
44
var answer = 0;
5-
let a=[];
6-
let b=[];
7-
citations.sort((A,B)=>A-B);
8-
9-
for(let i=citations.length;i>0;i--)
10-
{
11-
for(let j=0;j<citations.length;j++)
12-
{
13-
if(citations[j]>=i){
14-
a = citations.slice(0,j);
15-
b = citations.slice(j,citations.length);
16-
17-
if(a.length<=i&&b.length>=i){
5+
let a = [];
6+
let b = [];
7+
citations.sort((A, B) => A - B);
8+
9+
for (let i = citations.length; i > 0; i--) {
10+
for (let j = 0; j < citations.length; j++) {
11+
if (citations[j] >= i) {
12+
a = citations.slice(0, j);
13+
b = citations.slice(j, citations.length);
14+
15+
if (a.length <= i && b.length >= i) {
1816
return i;
1917
}
2018
}
@@ -29,13 +27,13 @@ function solution(citations) {
2927
function solution(citations) {
3028
citations = citations.sort(sorting);
3129
var i = 0;
32-
while(i + 1 <= citations[i]){
30+
while (i + 1 <= citations[i]) {
3331
i++;
3432
}
3533
return i;
3634

3735

38-
function sorting(a, b){
36+
function sorting(a, b) {
3937
return b - a;
4038
}
4139
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function solution(n, works) {
2+
works.sort((a,b)=>(b-a))
3+
4+
if(works.reduce((acc,val)=>acc+val ,0) < n )
5+
return 0;
6+
7+
while(n>0)
8+
{
9+
for(let i=0;;i++)
10+
{
11+
works[i]--;
12+
n--;
13+
if(works[i]+1 !== works[i+1] || n===0)
14+
break;
15+
}
16+
}
17+
return works.reduce((acc,val)=>acc+val*val ,0);
18+
}
19+
20+
//문제 출처 : https://programmers.co.kr/learn/courses/30/lessons/12927#
21+
//코드 정리 : https://velog.io/@khw970421/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EC%95%BC%EA%B7%BC-%EC%A7%80%EC%88%98

0 commit comments

Comments
 (0)