작성
·
353
0
function solution(k, arr) {
let answer = (sum = lt = 0);
for (let rt = 0; rt < arr.length; rt++) {
let leng = rt - lt + 1;
sum += arr[rt];
if (leng === k) {
answer = Math.max(answer, sum);
sum -= arr[lt++];
}
}
return answer;
}
let a = [12, 15, 11, 20, 25, 10, 20, 19, 13, 15];
console.log(solution(3, a));
투포인터로 풀어봤습니다.. 이렇게 풀어도 되는걸까요 ?