From e1196811c53c5b4d0fdb88d5697358907191e8bd Mon Sep 17 00:00:00 2001 From: jynam Date: Thu, 13 Apr 2023 02:10:32 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A0=95=EB=8B=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\236\220\353\245\264\352\270\260.js" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "PG/\353\241\244\354\274\200\354\235\264\355\201\254 \354\236\220\353\245\264\352\270\260.js" diff --git "a/PG/\353\241\244\354\274\200\354\235\264\355\201\254 \354\236\220\353\245\264\352\270\260.js" "b/PG/\353\241\244\354\274\200\354\235\264\355\201\254 \354\236\220\353\245\264\352\270\260.js" new file mode 100644 index 0000000..7dbd426 --- /dev/null +++ "b/PG/\353\241\244\354\274\200\354\235\264\355\201\254 \354\236\220\353\245\264\352\270\260.js" @@ -0,0 +1,25 @@ +function solution(topping) { + let answer = 0; + + const 철수 = new Map(); + const 동생 = new Map(); + + topping.forEach((t, index) => { + 철수.set(t, 철수.get(t) + 1 || 1); + }); + + topping.forEach((t) => { + 동생.set(t, 동생.get(t) + 1 || 1); + 철수.set(t, 철수.get(t) - 1); + + if (철수.get(t) < 1) { + 철수.delete(t); + } + + if (동생.size === 철수.size) { + answer++; + } + }); + + return answer; +}