From 5cb9a5888452afb9b76cacb78514129aabe3d487 Mon Sep 17 00:00:00 2001 From: luckylooky2 Date: Thu, 19 Oct 2023 20:38:39 +0900 Subject: [PATCH] =?UTF-8?q?10.19:=20sort,=20BigInt(=EC=B9=B4=EB=93=9C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- baekjoon/11652.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 baekjoon/11652.js diff --git a/baekjoon/11652.js b/baekjoon/11652.js new file mode 100644 index 0000000..dc33d4c --- /dev/null +++ b/baekjoon/11652.js @@ -0,0 +1,39 @@ +// 카드 : 정렬 +const arr = require("fs") + .readFileSync("/dev/stdin") + .toString() + .trim() + .split("\n") + // BigInt 배열 + .map((v) => BigInt(v)); +const n = arr.shift(); +// BigInt sort +const sorted = arr.sort((a, b) => { + if (a > b) return 1; + else if (a < b) return -1; + else return 0; +}); +let currValue = BigInt(arr[0]); +let currCount = 1; +let answerValue = -Infinity; +let answerCount = -Infinity; + +for (let i = 1; i < sorted.length; i++) { + if (BigInt(sorted[i]) === currValue) currCount++; + else { + if (currCount > answerCount) { + answerCount = currCount; + answerValue = currValue; + } + currValue = BigInt(sorted[i]); + currCount = 1; + } +} + +// 값이 변할 때 answer count를 바꿔줬기 때문에, 마지막 값은 바뀌지 않을 것이므로 마지막에 한 번 더 실행 +if (currCount > answerCount) { + answerCount = currCount; + answerValue = BigInt(currValue); +} + +console.log(String(answerValue));