Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 53b4411

Browse files
Merge pull request codeisneverodd#9 from createhb21/main_local
2022年03月30日 문제 풀이 추가합니다.
2 parents 8291459 + 6f0dafd commit 53b4411

File tree

5 files changed

+73
-3
lines changed

5 files changed

+73
-3
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
### Level 2 👨🏻‍💻(풀이 중..)
2424

2525
- 전체 문제 수: 64문제
26-
- 풀이 문제 수: 43문제(2022.03.28)
26+
- 풀이 문제 수: 44문제(2022.03.30)
2727
- 풀이 완료 예상 시점: 2022년 4월 중
2828

2929
### Level 3 👨🏻‍💻(풀이 중..)

‎level-2/K-번째수.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

‎level-2/가장-큰-수.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

‎level-2/기능개발.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

‎level-2/프린터.js‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff 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를 구현한 풀이를 추가합니다.
7191
function solution(priorities, location) {
7292
let answer = 0;
@@ -113,4 +133,4 @@ class Queue {
113133
size() {
114134
return this.rear - this.front
115135
}
116-
}
136+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /