작성
·
274
0
function solution(m, arr) {
let answer = 0;
let n = arr.length;
let p1 = 0;
let p2 = 1;
let tmp = arr[p1] + arr[p2];
while (p2 < n) {
if (tmp === m) {
answer++;
tmp = tmp - arr[p1++] + arr[++p2];
} else if (tmp < m) {
tmp += arr[++p2];
} else {
tmp -= arr[p1++];
}
}
return answer;
}
let a = [1, 2, 1, 3, 1, 1, 1, 2];
console.log(solution(6, a));