Skip to content

Commit 9dc021f

Browse files
authored
Create 956-tallest-billboard.js
1 parent eb6be43 commit 9dc021f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

956-tallest-billboard.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number[]} rods
3+
* @return {number}
4+
*/
5+
const tallestBillboard = function(rods) {
6+
const dp = {0 : 0}
7+
for(let el of rods) {
8+
for(let [diff, y] of Object.entries(dp)) {
9+
diff = +diff
10+
dp[diff + el] = Math.max(dp[diff + el] || 0, y)
11+
if(diff >= el) dp[diff - el] = Math.max(dp[diff - el] || 0, y + el)
12+
else dp[el - diff] = Math.max(dp[el - diff] || 0, y + diff)
13+
}
14+
}
15+
return dp['0']
16+
};

0 commit comments

Comments
 (0)