File tree 2 files changed +34
-15
lines changed
2 files changed +34
-15
lines changed Original file line number Diff line number Diff line change 2
2
3
3
function solution ( citations ) {
4
4
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 ) {
18
16
return i ;
19
17
}
20
18
}
@@ -29,13 +27,13 @@ function solution(citations) {
29
27
function solution ( citations ) {
30
28
citations = citations . sort ( sorting ) ;
31
29
var i = 0 ;
32
- while ( i + 1 <= citations [ i ] ) {
30
+ while ( i + 1 <= citations [ i ] ) {
33
31
i ++ ;
34
32
}
35
33
return i ;
36
34
37
35
38
- function sorting ( a , b ) {
36
+ function sorting ( a , b ) {
39
37
return b - a ;
40
38
}
41
39
}
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments