Skip to content

Commit

Permalink
#7 22.11.08 > 결혼식 복습
Browse files Browse the repository at this point in the history
  • Loading branch information
beurmuz committed Nov 8, 2022
1 parent a60a5dc commit ed77b61
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/inf/sort,greedy/9_rerere.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict";

function solution(arr) {
let answer = 0;
let timeTable = [];
for (let [come, out] of arr) {
timeTable.push([come, "c"]);
timeTable.push([out, "o"]);
}

timeTable.sort((a, b) => {
if (a[0] === b[0]) return b[1] - a[1]; // 만약 시간이 같으면, out -> come 순으로 정렬
return a[0] - b[0];
});

let people = 0;
for (let [time, status] of timeTable) {
if (status === "c") people++;
else people--;
answer = Math.max(people, answer);
}
return answer;
}

let arr = [
[14, 18],
[12, 16],
[15, 20],
[20, 30],
[5, 15],
];
console.log(solution(arr));
2 changes: 1 addition & 1 deletion src/inf/sort,greedy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
| 6 | O | 22.11.01 |
| 7 || 22.11.01 |
| 8 || 22.11.06 |
| 9 || 22.11.06😥 |
| 9 || 22.11.08😥 |
| 10 || 22.11.07 |
| 11 | X | 22.11.07😥 |
| 12 | X | 22.11.07😥 |

0 comments on commit ed77b61

Please sign in to comment.