Skip to content

Commit 4c137d8

Browse files
✨ feat(integerKnapsack): Check weights.
1 parent bf34027 commit 4c137d8

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/integerKnapsack.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const integerKnapsack = (v, w, n, W, m = new w.constructor(W + 1).fill(0)) => {
77
assert(m.length >= W + 1);
88
for (let i = 0; i < n; ++i) {
99
const x = w[i];
10+
assert(Number.isInteger(x) && x >= 0 && x <= W);
1011
const s = W - x;
1112
for (let j = 0; j <= s; ++j) {
1213
m[j] = Math.max(m[j], m[j + x] + v[i]);

0 commit comments

Comments
 (0)