Skip to content

Instantly share code, notes, and snippets.

@javi-aire
Created April 15, 2020 06:25
Show Gist options
  • Save javi-aire/23c0511015dcfbd7a04bf019d4e023df to your computer and use it in GitHub Desktop.
Save javi-aire/23c0511015dcfbd7a04bf019d4e023df to your computer and use it in GitHub Desktop.
Problem 13/30 of LeetCode 30-day challenge
let findMaxLength = function(nums) {
const map = new Map();
map.set(0, -1);
let count = 0,
max = 0;
for(let i = 0; i < nums.length; i++) {
if(nums[i] === 0){
count--;
} else {
count++;
}
max = map.has(count) ? Math.max(max, i - map.get(count)) : max;
if (!map.has(count) || map.has(count) === -1) {
map.set(count, i);
}
}
return max;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment