Skip to content

Commit

Permalink
#7 22.11.06 > 회의실 배정 다시풀기
Browse files Browse the repository at this point in the history
  • Loading branch information
beurmuz committed Nov 6, 2022
1 parent 5f22ce7 commit 035e3f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions src/inf/sort,greedy/8_rere.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
function solution(arr) {
let answer = [];

// 회의 종료 시간 기준으로 정렬
arr.sort((a, b) => {
if (a[1] === b[1]) {
return a[0] - b[0];
} else {
return a[1] - b[1];
}
if (a[1] === b[1]) return a[0] - b[0];
return a[1] - b[1];
});

let endTime = 0;
for (let x of arr) {
if (x[0] >= endTime) {
answer.push(x);
endTime = x[1];
// 종료 시간보다 크거나 같은 시간만 찾기
let pivot = 0;
for (let [start, end] of arr) {
if (start >= pivot) {
answer.push([start, end]);
pivot = end;
}
}
return answer.length;
Expand Down
2 changes: 1 addition & 1 deletion src/inf/sort,greedy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
| 5 | 몰라몰라몰라 | |
| 6 | O | 22.11.01 |
| 7 || 22.11.01 |
| 8 || 22.11.05 |
| 8 || 22.11.06 |
| 9 || O |
| 10 || O |
| 11 | X | O |
Expand Down

0 comments on commit 035e3f9

Please sign in to comment.