Skip to content

Commit

Permalink
10.19: sort, BigInt(카드)
Browse files Browse the repository at this point in the history
  • Loading branch information
luckylooky2 committed Oct 19, 2023
1 parent 1e118e6 commit 5cb9a58
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions baekjoon/11652.js
Original file line number Diff line number Diff line change
@@ -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));

0 comments on commit 5cb9a58

Please sign in to comment.