From cc18d971bbf10334369d359622f4b4aaff5d59e9 Mon Sep 17 00:00:00 2001 From: JengYoung Date: Fri, 3 May 2024 08:29:28 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EC=8B=9C=EC=86=8C=20=EC=A7=9D?= =?UTF-8?q?=EA=BF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\206\214 \354\247\235\352\277\215.md" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "\355\231\251\354\236\254\354\230\201/\354\213\234\354\206\214 \354\247\235\352\277\215.md" diff --git "a/\355\231\251\354\236\254\354\230\201/\354\213\234\354\206\214 \354\247\235\352\277\215.md" "b/\355\231\251\354\236\254\354\230\201/\354\213\234\354\206\214 \354\247\235\352\277\215.md" new file mode 100644 index 0000000..53e7d26 --- /dev/null +++ "b/\355\231\251\354\236\254\354\230\201/\354\213\234\354\206\214 \354\247\235\352\277\215.md" @@ -0,0 +1,35 @@ +```js +function solution(weights) { + let result = 0; + + const map = new Map(); + + // 먼저 map에 weight 정보를 추가 + weights.forEach((weight) => { + map.set(weight, (map.get(weight) ?? 0) + 1); + }); + + map.forEach((value, key) => { + // 상대편의 경우의 수를 모두 추려냄. + [key, (key * 3) / 2, (key * 4) / 3, key * 2].forEach((partnerWeight) => { + // 만약 상대방의 몸무게에 관하여 정보가 없으면, 짝꿍이 될 수 없음. + if (!map.has(partnerWeight)) { + return; + } + + // 몸무게가 같은 경우 = N개 중 2개를 뽑아내는 조합 + if (key === partnerWeight) { + result += (value * (value - 1)) / 2; + return; + } + + const partnerWeightCount = map.get(partnerWeight); + + // 몸무게가 다른 경우 = 서로의 곱만큼 경우의 수 가능 + result += partnerWeightCount * value; + }); + }); + + return result; +} +``` From e3d69603ad5575135c90ca7691ee28c73651bea9 Mon Sep 17 00:00:00 2001 From: JengYoung Date: Fri, 3 May 2024 08:29:55 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=ED=83=9D=EB=B0=B0=20=EC=83=81?= =?UTF-8?q?=EC=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\353\260\260 \354\203\201\354\236\220.md" | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 "\355\231\251\354\236\254\354\230\201/\355\203\235\353\260\260 \354\203\201\354\236\220.md" diff --git "a/\355\231\251\354\236\254\354\230\201/\355\203\235\353\260\260 \354\203\201\354\236\220.md" "b/\355\231\251\354\236\254\354\230\201/\355\203\235\353\260\260 \354\203\201\354\236\220.md" new file mode 100644 index 0000000..579a630 --- /dev/null +++ "b/\355\231\251\354\236\254\354\230\201/\355\203\235\353\260\260 \354\203\201\354\236\220.md" @@ -0,0 +1,66 @@ +```js +class Queue { + constructor() { + this.queue = []; + this.front = 0; + this.rear = 0; + } + enqueue(value) { + this.queue[this.rear++] = value; + } + dequeue() { + const value = this.queue[this.front]; + delete this.queue[this.front]; + this.front += 1; + return value; + } + get peek() { + return this.queue[this.front]; + } + get size() { + return this.rear - this.front; + } +} + +/** + * 메인컨테이너벨트 - 맨 앞쪽부터 빼내는 방식 = 큐 + * 보조컨테이너벨트 - 후입선출의 방식 = 스택 + */ +function solution(order) { + let result = 0; + + const mainContainerBelt = new Queue(); + const subContainerBelt = []; + + for (let i = 1; i <= order.length; i += 1) { + mainContainerBelt.enqueue(i); + } + + for (let now of order) { + while (mainContainerBelt.size && mainContainerBelt.peek < now) { + const keep = mainContainerBelt.dequeue(); + subContainerBelt.push(keep); + } + + if (mainContainerBelt.peek === now) { + mainContainerBelt.dequeue(); + + result += 1; + + continue; + } + + if (subContainerBelt.at(-1) === now) { + subContainerBelt.pop(); + + result += 1; + + continue; + } + + break; + } + + return result; +} +```