Skip to content

Instantly share code, notes, and snippets.

@iJustErikk
Created December 7, 2020 17:48
Show Gist options
  • Save iJustErikk/7916c676b74052717a313624a3829622 to your computer and use it in GitHub Desktop.
Save iJustErikk/7916c676b74052717a313624a3829622 to your computer and use it in GitHub Desktop.
const canSum = (goal, nums) => {
const table = new Array(goal + 1).fill(false);
table[0] = true;
for (let i = 0; i <= goal; i += 1) {
// i is current value
// if i is true, then i + nums[j] is also true
if (table[i]) {
for (let j = 0; j < nums.length; j += 1) {
const currentVal = i + nums[j];
if (currentVal <= goal) table[currentVal] = true;
}
}
}
return table[goal];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment