[LeetCode]343. Integer Break

Hint:3越多越好
Solution如下

class Solution {
public:
    int integerBreak(int n) {
        if(n == 2) return 1;
        if(n == 3) return 2;
        int ret = 1;
        while( n>4 )
        {
            ret *= 3;
            n -= 3;
        }
        return ret * n;
    }
};

猜你喜欢

转载自blog.csdn.net/qq_31359295/article/details/78461534