Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- useRef()
- charAt()
- Number()
- includes()
- getday()
- setDate
- map()
- isNaN()
- filter()
- 차집합
- new Date()
- Eventlitener
- sort()
- indexOf()
- 교집합
- useEffect()
- substring()
- Math.sqrt()
- 소수점 올림내림
- reat if문
- React
- slice()
- parseInt()
- 항해99솔직후기 #항해99장점 #항해99단점 #부트캠프추천
- repeat()
- Math.floor()
- jsx반복문
- 3진수
- useState()
- toUpperCase()
Archives
- Today
- Total
개발자로 전향중
[백준] 통계 본문
// Statistics
// For submit
// const fs = require('fs');
// const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n').map(num => parseInt(num));
// For local test
// const input = [5, 1, 3, 8, -2, 2];
// const input = [1, 4000];
const input = [5, -1, -2, -3, -1, -2];
const N = input.shift();
const sortedNumArr = input.sort((a, b) => a - b);
const numMap = {};
for (let num of sortedNumArr) {
if (numMap[num]) {
numMap[num] = numMap[num] + 1;
} else {
numMap[num] = 1;
}
}
let hitMaxNum = Math.max.apply(null, Object.values(numMap));
let hitMaxNumArr = [];
let hitMaxNumResult = 0;
for (let numKey in numMap) {
if (numMap[numKey] === hitMaxNum) {
hitMaxNumArr.push(numKey);
}
}
if (hitMaxNumArr.length > 1) {
hitMaxNumArr = hitMaxNumArr.sort((a, b) => a - b);
hitMaxNumResult = hitMaxNumArr[1];
} else {
hitMaxNumResult = hitMaxNumArr[0];
}
const avg = Math.round(input.reduce((acc, num) => (acc += num), 0) / N);
const center = input[Math.floor(input.length / 2)];
const maxSubMin = sortedNumArr[sortedNumArr.length - 1] - sortedNumArr[0];
console.log(avg);
console.log(center);
console.log(hitMaxNumResult);
console.log(maxSubMin);
'자료구조&알고리즘' 카테고리의 다른 글
빅오표기법의 이해 (0) | 2022.08.30 |
---|---|
시간 복잡도(Time Complexity) 및 공간 복잡도(Space Complexity) (0) | 2022.08.29 |
[백준] 1149 RGB거리 (0) | 2022.03.25 |
[백준] 11053번 가장 긴 증가하는 부분 수열 (0) | 2022.03.23 |
[백준] 분해합 (0) | 2022.03.21 |