0ms, Math solution


  • 0
    public class Solution {
        public int integerBreak(int n) {
            if (n <= 3) return n == 3 ? 2:1;
            int numOfThree = n/3;
            int carry = n%3;
            int numOfFour = 0;
            if (carry == 1) {
                numOfThree--;
                numOfFour++;
            }
            int res = 1;
            for (int i = 0; i < numOfThree; i++) {
                res *= 3;
            }
            if (numOfFour == 1) res *= 4;
            else if (carry == 2) res *= 2;
            return res;
        }
    }
    

Log in to reply
 

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