function subarraySum(num, k) {
let counter = 0;
let start = 0;
let end = 0;
let summ = nums[0];
while (start < nums.length) {
if (start > nums.length) {
end = start;
summ = nums[start];
}
if (summ < k) {
end++;
if (end === nums.length)
break;
summ += nums[end];
} else if(summ > k) {
summ -= nums[start];
start++;
} else {
counter++;
summ -= nums[start];
start++;
}
}
return counter;
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter