Skip to content

Commit dbdd0e5

Browse files
committed
Bronze2: 브루트포스, 투포인터방식으로풀이
1 parent 219fd7e commit dbdd0e5

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const fs = require("fs");
2+
const filePath =
3+
process.platform === "linux" ? "/dev/stdin" : "./Z_Test/input.txt";
4+
let input = fs.readFileSync(filePath).toString().trim().split("\n");
5+
6+
const arr = input.map((item) => +item);
7+
8+
const solution = (arr) => {
9+
left = 0;
10+
right = 0;
11+
const heightSum = arr.reduce((cur, acc) => cur + acc);
12+
13+
while (right < arr.length) {
14+
if (right === arr.length - 1) {
15+
left += 1;
16+
right = left;
17+
}
18+
19+
right += 1;
20+
if (heightSum - arr[left] - arr[right] === 100) {
21+
arr.map((item, index) => {
22+
if (index !== right && index !== left) {
23+
console.log(item);
24+
}
25+
});
26+
break;
27+
}
28+
}
29+
};
30+
31+
solution(arr);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
8
2+
6
3+
5
4+
1
5+
37
6+
30
7+
28
8+
22
9+
36

0 commit comments

Comments
 (0)