Skip to content

Commit 9587c01

Browse files
committed
85차 1번 문제풀이
1 parent 1e08fc9 commit 9587c01

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

live8/test85/문제1/이상민.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const input = require("fs")
2+
.readFileSync(process.platform === "linux" ? "/dev/stdin" : "./input.txt")
3+
.toString()
4+
.trim()
5+
.split("\n");
6+
7+
const answer = [];
8+
const arr = [];
9+
10+
for (let i = 2; i < input.length; i += 2) {
11+
arr.push(input[i].split(" ").map(Number));
12+
}
13+
14+
for (let i = 0; i < arr.length; i++) {
15+
const tmp = arr[i].sort((a, b) => a - b);
16+
const n = tmp.length;
17+
let count = 0;
18+
19+
for (let j = 1; j < n - 1; j++) {
20+
const mid = tmp[j];
21+
let left = j - 1;
22+
let right = j + 1;
23+
24+
while (left >= 0 && right < n) {
25+
const leftDiff = mid - tmp[left];
26+
const rightDiff = tmp[right] - mid;
27+
28+
if (leftDiff === rightDiff) {
29+
count++;
30+
left--;
31+
right++;
32+
} else if (leftDiff < rightDiff) {
33+
left--;
34+
} else {
35+
right++;
36+
}
37+
}
38+
}
39+
answer.push(count);
40+
}
41+
42+
console.log(answer.join("\n"));

0 commit comments

Comments
 (0)