题解 | #剪绳子#
剪绳子
http://www.nowcoder.com/practice/57d85990ba5b440ab888fc72b0751bf8
function cutRope(number)
{
if(number === 2){
return 1
}
if(number === 3){
return 2
}if(number === 4){
return 4
}
if(number === 5){
return 6
}
if(number === 6){
return 9
}
return 3*cutRope(number-3) // 需要特殊处理小于7的情况,其他情况用3迭代
}
module.exports = {
cutRope : cutRope
};