5 lines simple java - math w/o DP


  • 0
    L
    public class Solution {
        public int integerBreak(int n) {
            if(n==2) return 1;
            if(n==3) return 2;
            if(n%3==0) return (int) Math.pow(3,n/3);
            else if(n%3==1) return (int) Math.pow(3,n/3-1)*4;
            else return (int) Math.pow(3,n/3)*2;
        }
    }
    

  • 0

    would you add some explanation ? thanks


Log in to reply
 

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