Skip to content

Commit 3e0b17a

Browse files
author
Eric
committed
89차 2번 문제풀이
1 parent 9afb746 commit 3e0b17a

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

live8/test89/문제2/황장현.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((el) => el.split(' ').map(Number));
7+
8+
function solution(input) {
9+
const [N, M] = input[0];
10+
const A = input[1];
11+
12+
let answer = 0;
13+
for (let i = 0; i < N; i++) {
14+
let p1 = i;
15+
let sum = 0;
16+
17+
while (p1 < N) {
18+
sum += A[p1];
19+
20+
if (sum === M) {
21+
answer++;
22+
break;
23+
}
24+
if (sum > M) {
25+
break;
26+
}
27+
p1++;
28+
}
29+
}
30+
return answer;
31+
}
32+
33+
console.log(solution(input));

0 commit comments

Comments
 (0)