Simple JAVA Solution


  • 0
    D
    public class Solution {
        public int integerBreak(int n) {
            int[] res = new int[59];
            res[1] = 1;
            res[2] = 1;
            for (int i = 3;i < res.length;++i) {
                int max = Integer.MIN_VALUE;
                for (int j = i - 1;j >= 1;--j) {
                    int temp = (res[j] > j ? res[j] : j) * (i - j);
                    if (temp > max) {
                        max = temp;
                    }
                }
                res[i] = max;
            }
            return res[n];
        }
    }
    

Log in to reply
 

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