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

2022年03月30日 문제 풀이 추가합니다. #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
codeisneverodd merged 4 commits into codeisneverodd:main from createhb21:main_local
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
### Level 2 👨🏻‍💻(풀이 중..)

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

### Level 3 👨🏻‍💻(풀이 중..)
Expand Down
13 changes: 13 additions & 0 deletions level-2/K-번째수.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - createhb21

function solution(array, commands) {
let answer = [];
for(let i = 0; i < commands.length; i++){
let eachCommand = commands[i]
let slice = array.slice(eachCommand[0] - 1, eachCommand[1]);
answer.push(slice.sort((a, b) => a - b)[eachCommand[2] - 1])
}
return answer;
}
9 changes: 9 additions & 0 deletions level-2/가장-큰-수.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ const sortFunc = (a, b) => {
const compareA = parseInt(a.toString() + b.toString())
const compareB = parseInt(b.toString() + a.toString())
return compareB - compareA
}


// 정담 2 - createhb21
function solution(numbers) {
let stringNum =
numbers.map((el) => el + '').sort((a,b) => (b+a) - (a+b));

return stringNum[0] === '0' ? '0' : stringNum.join('');
}
28 changes: 28 additions & 0 deletions level-2/기능개발.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,31 @@ function solution(progresses, speeds) {
}
return answer;
}



// 정답 4 - createhb21
function solution(progresses, speeds) {
// answer은 각 배포 때 함께 배포되는 기능의 수를 담은 배열
var answer = [];
// 각각의 기능이 몇 일 소요되는지 담은 큐
let queue = [];

for (let i = 0; i < speeds.length; i++) {
// 각각의 기능이 몇 일 걸리는지 계산
let task = Math.ceil((100 - progresses[i]) / speeds[i]);
// 위 계산한 결과값(작업일)을 모두 큐에 넣어준다.
queue.push(task);

// 그 다음 작업이 queue[0]보다 작거나 같을 경우, queue.push()
// 그 다음 작업이 queue[0]보다 클 경우, queue의 사이즈만큼 answer.push(), queue 초기화
if(task > queue[0]) {
answer.push(queue.length-1);
// 큐 초기화
queue = [task];
}
}

answer.push(queue.length);
return answer;
}
24 changes: 22 additions & 2 deletions level-2/프린터.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,27 @@ function solution(priorities, location) {
return answer
}

//정답 4 - codeisneverodd
// 정답 4 - createhb21
function solution(priorities, location) {
var answer = priorities.map((priority, index) => {
return {
index,
priority
};
});

let queue = [];

while(answer.length > 0){
const first = answer.shift();
const isPriority = answer.some((p) => p.priority > first.priority);
isPriority ? answer.push(first) : queue.push(first);
}
const idx = queue.findIndex(p => p.index === location) + 1;
return idx;
}

//정답 5 - codeisneverodd
//shift를 사용하지 않고 queue를 구현한 풀이를 추가합니다.
function solution(priorities, location) {
let answer = 0;
Expand Down Expand Up @@ -113,4 +133,4 @@ class Queue {
size() {
return this.rear - this.front
}
}
}

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