File tree Expand file tree Collapse file tree 5 files changed +73
-3
lines changed Expand file tree Collapse file tree 5 files changed +73
-3
lines changed Original file line number Diff line number Diff line change 2323### Level 2 👨🏻💻(풀이 중..)
2424
2525- 전체 문제 수: 64문제
26- - 풀이 문제 수: 43문제 (2022.03.28 )
26+ - 풀이 문제 수: 44문제 (2022.03.30 )
2727- 풀이 완료 예상 시점: 2022년 4월 중
2828
2929### Level 3 👨🏻💻(풀이 중..)
Original file line number Diff line number Diff line change 1+ //https://github.com/codeisneverodd/programmers-coding-test
2+ //완벽한 정답이 아닙니다.
3+ //정답 1 - createhb21
4+
5+ function solution ( array , commands ) {
6+ let answer = [ ] ;
7+ for ( let i = 0 ; i < commands . length ; i ++ ) {
8+ let eachCommand = commands [ i ]
9+ let slice = array . slice ( eachCommand [ 0 ] - 1 , eachCommand [ 1 ] ) ;
10+ answer . push ( slice . sort ( ( a , b ) => a - b ) [ eachCommand [ 2 ] - 1 ] )
11+ }
12+ return answer ;
13+ }
Original file line number Diff line number Diff line change @@ -13,4 +13,13 @@ const sortFunc = (a, b) => {
1313 const compareA = parseInt ( a . toString ( ) + b . toString ( ) )
1414 const compareB = parseInt ( b . toString ( ) + a . toString ( ) )
1515 return compareB - compareA
16+ }
17+
18+
19+ // 정담 2 - createhb21
20+ function solution ( numbers ) {
21+ let stringNum =
22+ numbers . map ( ( el ) => el + '' ) . sort ( ( a , b ) => ( b + a ) - ( a + b ) ) ;
23+
24+ return stringNum [ 0 ] === '0' ? '0' : stringNum . join ( '' ) ;
1625}
Original file line number Diff line number Diff line change @@ -61,3 +61,31 @@ function solution(progresses, speeds) {
6161 }
6262 return answer ;
6363}
64+
65+
66+
67+ // 정답 4 - createhb21
68+ function solution ( progresses , speeds ) {
69+ // answer은 각 배포 때 함께 배포되는 기능의 수를 담은 배열
70+ var answer = [ ] ;
71+ // 각각의 기능이 몇 일 소요되는지 담은 큐
72+ let queue = [ ] ;
73+
74+ for ( let i = 0 ; i < speeds . length ; i ++ ) {
75+ // 각각의 기능이 몇 일 걸리는지 계산
76+ let task = Math . ceil ( ( 100 - progresses [ i ] ) / speeds [ i ] ) ;
77+ // 위 계산한 결과값(작업일)을 모두 큐에 넣어준다.
78+ queue . push ( task ) ;
79+
80+ // 그 다음 작업이 queue[0]보다 작거나 같을 경우, queue.push()
81+ // 그 다음 작업이 queue[0]보다 클 경우, queue의 사이즈만큼 answer.push(), queue 초기화
82+ if ( task > queue [ 0 ] ) {
83+ answer . push ( queue . length - 1 ) ;
84+ // 큐 초기화
85+ queue = [ task ] ;
86+ }
87+ }
88+
89+ answer . push ( queue . length ) ;
90+ return answer ;
91+ }
Original file line number Diff line number Diff line change @@ -66,7 +66,27 @@ function solution(priorities, location) {
6666 return answer
6767}
6868
69- //정답 4 - codeisneverodd
69+ // 정답 4 - createhb21
70+ function solution ( priorities , location ) {
71+ var answer = priorities . map ( ( priority , index ) => {
72+ return {
73+ index,
74+ priority
75+ } ;
76+ } ) ;
77+
78+ let queue = [ ] ;
79+
80+ while ( answer . length > 0 ) {
81+ const first = answer . shift ( ) ;
82+ const isPriority = answer . some ( ( p ) => p . priority > first . priority ) ;
83+ isPriority ? answer . push ( first ) : queue . push ( first ) ;
84+ }
85+ const idx = queue . findIndex ( p => p . index === location ) + 1 ;
86+ return idx ;
87+ }
88+
89+ //정답 5 - codeisneverodd
7090//shift를 사용하지 않고 queue를 구현한 풀이를 추가합니다.
7191function solution ( priorities , location ) {
7292 let answer = 0 ;
@@ -113,4 +133,4 @@ class Queue {
113133 size ( ) {
114134 return this . rear - this . front
115135 }
116- }
136+ }
You can’t perform that action at this time.
0 commit comments