题解 | #剪绳子#
剪绳子
https://www.nowcoder.com/practice/57d85990ba5b440ab888fc72b0751bf8
class Solution{ public: int cutRope(int n){ int result; if(n%3==0){ result = pow(3, n/3); } if(n%3 == 1){ result = pow(3, (n-4)/3); result *= 4; } if(n%3 == 2){ result = pow(3, n/3); result *= 2; } return result; } };