We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 142c98c commit 569e554Copy full SHA for 569e554
Dynamic-Programming/RodCutting.js
@@ -4,6 +4,18 @@
4
*/
5
6
export function rodCut(prices, n) {
7
+ if (!Array.isArray(prices)) {
8
+ throw new TypeError('Prices must be an array')
9
+ }
10
+
11
+ if (!Number.isInteger(n) || n < 0) {
12
+ throw new TypeError('Rod length must be a non-negative integer')
13
14
15
+ if (n === 0) {
16
+ return 0
17
18
19
const memo = new Array(n + 1)
20
memo[0] = 0
21
0 commit comments