Leetcode 343 整数拆分

67 阅读1分钟

Leetcode 343 整数拆分

class Solution {

    public int integerBreak(int n) {
        int[] flags = new int[1+n];
        flags[1]=1;
        int temp = 0;
       for(int i=2;i<=n;i++){
           for(int j=1;j<i;j++){
               temp = Math.max(temp,Math.max(flags[j]*(i-j),j*(i-j)));
           }
           flags[i]=temp;
       }
        return flags[n];
    }
}