From 5f22ce7323aaa4bb235eb962b9f137f39f9603f1 Mon Sep 17 00:00:00 2001 From: beurmuz Date: Sat, 5 Nov 2022 23:29:54 +0900 Subject: [PATCH] =?UTF-8?q?#7=2022.11.05=20>=20=ED=9A=8C=EC=9D=98=EC=8B=A4?= =?UTF-8?q?=20=EB=B0=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/inf/sort,greedy/8_rere.js | 31 +++++++++++++++++++++++++++++++ src/inf/sort,greedy/README.md | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/inf/sort,greedy/8_rere.js diff --git a/src/inf/sort,greedy/8_rere.js b/src/inf/sort,greedy/8_rere.js new file mode 100644 index 00000000..2ba875c1 --- /dev/null +++ b/src/inf/sort,greedy/8_rere.js @@ -0,0 +1,31 @@ +"use strict"; + +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]; + } + }); + + let endTime = 0; + for (let x of arr) { + if (x[0] >= endTime) { + answer.push(x); + endTime = x[1]; + } + } + return answer.length; +} + +let arr = [ + [1, 4], + [2, 3], + [3, 5], + [4, 6], + [5, 7], +]; +console.log(solution(arr)); diff --git a/src/inf/sort,greedy/README.md b/src/inf/sort,greedy/README.md index 11608d2e..94f4f34f 100644 --- a/src/inf/sort,greedy/README.md +++ b/src/inf/sort,greedy/README.md @@ -21,7 +21,7 @@ | 5 | 몰라몰라몰라 | | | 6 | O | 22.11.01 | | 7 | △ | 22.11.01 | -| 8 | △ | O | +| 8 | △ | 22.11.05 | | 9 | △ | O | | 10 | △ | O | | 11 | X | O |