-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e118e6
commit 5cb9a58
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |