Friday, October 13, 2017

343. Integer Break

https://leetcode.com/problems/integer-break/description/
    int integerBreak(int n) {
        if(n == 2)
            return 1;
        else if(n == 3)
            return 2;
        else if(n%3 == 0)
            return (int) pow(3, n/3);
        else if(n%3 == 1)
            return 2 * 2 * (int) pow(3, (n - 4) / 3);
        else
            return 2 * (int) pow(3, n/3);
    }

No comments:

Post a Comment