From e201fc909158dd5ea1ea7377f50aea07255c26de Mon Sep 17 00:00:00 2001 From: Dongmin <122417731+cdm1263@users.noreply.github.com> Date: Mon, 8 Jan 2024 23:41:34 +0900 Subject: [PATCH] =?UTF-8?q?[PGM]=20=EB=8D=94=20=EB=A7=B5=EA=B2=8C=20/=20Le?= =?UTF-8?q?vel=202=20/=20=EC=8B=A4=ED=8C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\215\224 \353\247\265\352\262\214.js" | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 "dongmin/\353\215\224 \353\247\265\352\262\214.js" diff --git "a/dongmin/\353\215\224 \353\247\265\352\262\214.js" "b/dongmin/\353\215\224 \353\247\265\352\262\214.js" new file mode 100644 index 0000000..b7dc8be --- /dev/null +++ "b/dongmin/\353\215\224 \353\247\265\352\262\214.js" @@ -0,0 +1,18 @@ +function solution(scoville, K) { + let count = 0; + const hash = scoville.reduce((a, b) => { + a[b] = b; + return a; + }, {}); + + while (Object.values(hash)[0] < K) { + const arr = Object.values(hash); + const newFood = arr[0] + arr[1] * 2; + delete hash[arr[0]]; + delete hash[arr[1]]; + count += 1; + hash[newFood] = newFood; + } + + return count; +}