인프런 커뮤니티 질문&답변
이런 풀이 괜찮을 까요?
작성
·
153
0
function solution(m, arr) {
let [left, right] = [0, 1];
let sum = arr[left];
let result = 0;
while (right <= arr.length) {
if (sum < m) {
sum += arr[right++];
} else if (sum > m) {
sum -= arr[left++];
} else {
sum -= arr[left++];
result++;
}
}
return result;
}
퀴즈
What is the main reason why two-pointer or sliding window techniques are more efficient than nested loops?
Because it uses less memory?
Is it because the code is shorter?
Is it because it achieves O(N) time complexity in most cases?
Is it because it's not affected by the input data size?





