0ms 5-line math solution

  • 3
    class Solution {
        int integerBreak(int n) {
            const vector<int> ref{1,1,1,2,4};
            if(n<=4) return ref[n];
            if(n%3==0) return pow(3, n/3);
            if(n%3==1) return 4*pow(3, n/3-1);
            if(n%3==2) return 2*pow(3, n/3);

Log in to reply

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