Share my C++ solution


  • 0
    W
    class Solution {
    public:
        int integerBreak(int n) {
            if(n < 4) return n - 1;
            int threes = n / 3, twos = 0, remain = n % 3;
            if(remain == 1) {
                threes--;
                twos = 2;
            } else if(remain == 2) {
                twos = 1;
            }
            return ((int)pow(3, threes)) << twos;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.