Maximum Number of Non-Overlapping Subarrays With Sum Equals Target LeetCode solution in JavaScript

1
var maxNonOverlapping = function (nums, target) {
2
const seen = new Set();
3
let total = 0,
4
result = 0;
5

6
for (let n of nums) {
7
total += n;
8

9
if (total === target || seen.has(total - target)) {
10
total = 0;
11
result++;
12
seen.clear();
13
} else seen.add(total);
14
}
15
return result;
16
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0