剑指 Offer 14- II. 剪绳子 II
作者:互联网
题目
代码
class Solution {
public:
int cuttingRope(int n) {
if(n <= 3)
return 1 * (n - 1);
long res = 1;
if(n % 3 == 1)
res = 4, n -= 4;
else if( n % 3 == 2)
res = 2, n -= 2;
while(n)
res *= 3, res %= 1000000007, n -= 3;
return res;
}
};
标签:14,Offer,int,绳子,Solution,II 来源: https://www.cnblogs.com/meww/p/16170035.html