Skip to content

Commit f0a4792

Browse files
author
gyeong-hyeon-kim
committed
Solved 2 problems
1 parent a92dba5 commit f0a4792

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

level-2/기능개발.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
//정답 1 - 시간 복잡도 감소
4+
function solution(progresses, speeds) {
5+
var answer = [];
6+
const remainDays = progresses.map((prog, index)=> Math.ceil((100-prog)/speeds[index]))
7+
console.log(remainDays)
8+
let maxDay = remainDays[0]
9+
answer.push(0)
10+
for(let i=0; i<remainDays.length; i++){
11+
if(remainDays[i] <= maxDay){
12+
answer[answer.length-1] += 1
13+
}else{
14+
answer.push(1)
15+
maxDay = remainDays[i]
16+
}
17+
}
18+
return answer;
19+
}
20+
21+
//정답 2
22+
function solution(progresses, speeds) {
23+
var answer = [];
24+
while(progresses.length > 0){
25+
let done = 0
26+
progresses = progresses.map((prog, index)=> prog + speeds[index])
27+
const length = progresses.length
28+
for(let i=0; i<length; i++){
29+
if(progresses[0] >= 100) {
30+
progresses.shift()
31+
speeds.shift()
32+
done += 1
33+
}else{
34+
break
35+
}
36+
}
37+
if(done > 0) answer.push(done)
38+
}
39+
return answer;
40+
}

level-2/프린터.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
//정답 1
4+
function solution(priorities, location) {
5+
var answer = 0;
6+
let documents = priorities.map((priority, index)=> ({location: index, priority: priority}))
7+
let locationPrinted = false
8+
while(!locationPrinted){
9+
const shifted = documents.shift()
10+
let printAvailable = true
11+
if(documents.some((document)=> shifted.priority < document.priority)) printAvailable = false
12+
if(printAvailable){
13+
answer += 1
14+
if(shifted.location === location) locationPrinted = true
15+
}else{
16+
documents.push(shifted)
17+
}
18+
}
19+
return answer;
20+
}
21+
//정답 2
22+
function solution(priorities, location) {
23+
var answer = 0;
24+
let documents = priorities.map((priority, documentLocation)=> [documentLocation,priority])
25+
let locationPrinted = false
26+
while(!locationPrinted){
27+
const shifted = documents.shift()
28+
let printAvailable = true
29+
for(let i=0; i<documents.length; i++){
30+
if(shifted[1] < documents[i][1]){
31+
printAvailable = false
32+
break
33+
}
34+
}
35+
if(printAvailable){
36+
answer += 1
37+
if(shifted[0] === location) locationPrinted = true
38+
}else{
39+
documents.push(shifted)
40+
}
41+
}
42+
return answer;
43+
}

0 commit comments

Comments
 (0)