题解 | #剪绳子#
剪绳子
https://www.nowcoder.com/practice/57d85990ba5b440ab888fc72b0751bf8
function max(a,b){ if(a>b) return a else return b } function cutRope(number) { if(number<=3) return number-1 var maxlength=[] maxlength[1]=1 maxlength[2]=2 maxlength[3]=3 maxlength[4]=4 for(let i=5;i<=number;i++){ for(let j=1;j<i;j++) maxlength[i]=max(maxlength[i],j*maxlength[i-j]) } return maxlength[number] } module.exports = { cutRope : cutRope };