resolved style issues in the code

This commit is contained in:
raghhavtaneja
2021-10-12 16:55:56 +05:30
parent 0ae960c4ee
commit 5210273104
2 changed files with 17 additions and 22 deletions

View File

@ -1,21 +1,17 @@
/*
/*
* You are given a rod of 'n' length and an array of prices associated with all the lengths less than 'n'.
* Find the maximum profit possible by cutting the rod and selling the pieces.
*/
export function rodCut(prices, n){
let memo = new Array(n + 1);
memo[0] = 0;
for (let i = 1; i<=n; i++)
{
let max_val = Number.MIN_VALUE;
for (let j = 0; j < i; j++)
max_val = Math.max(max_val, prices[j] + memo[i - j - 1]);
memo[i] = max_val;
}
return memo[n];
}
export function rodCut (prices, n) {
const memo = new Array(n + 1)
memo[0] = 0
for (let i = 1; i <= n; i++) {
let maxVal = Number.MIN_VALUE
for (let j = 0; j < i; j++) { maxVal = Math.max(maxVal, prices[j] + memo[i - j - 1]) }
memo[i] = maxVal
}
return memo[n]
}