- n%3 == 1, 除3之外有两个2
- n%3 == 2, 除3之外有一个2
- n%3 == 0,全部是3
tqltql
class Solution {
public:
int maxProductAfterCutting(int n) {
if (n <= 3) return 1 * (n-1);
int res = 1;
if (n % 3 == 1) res *= 4, n -= 4;
if (n % 3 == 2) res *= 2, n -= 2;
while(n) {
res *= 3, n -= 3;
}
return res;
}
};