class Solution {
public:
int integerBreak(int n) {
if (n == 2) {
return 1;
}
if (n == 3) {
return 2;
}
int i = (n-4)/3;
int ret = 0;
if ((n-4)%3 == 0) {
ret = 4*(int)pow(3, i);
} else if ((n-4)%3 == 1) {
ret = 2*(int)pow(3, i+1);
} else {
ret = (int)pow(3, i+2);
}
return ret;
}
};
LeetCode 343. Integer Break
最新推荐文章于 2022-03-08 09:21:22 发布