작성
·
176
0
function solution(m, arr){
let answer=0, sum=0, lt=0, rt=0;
let n = arr.length
while(rt < n){
if(sum ===0) sum+=arr[lt]
if(sum > m){
sum -= arr[lt++]
} else{
answer+=(rt-lt+1)
rt++
sum += arr[rt]
}
}
return answer;
}
let a=[1, 3, 1, 2, 3];
console.log(solution(5, a));