Zero Sum Subarray
Zero Sum Subarray
// O(n) time | O(n) space - where n is the length of nums
function zeroSumSubarray(nums) {
const sums = new Set([0]);
let currentSum = 0;
for (const num of nums) {
currentSum += num;
if (sums.has(currentSum)) return true;
sums.add(currentSum);
}
return false;
}
// Do not edit the line below.
exports.zeroSumSubarray = zeroSumSubarray;
Last updated