[JAVA] DP / T : O(N^2), S : O(N)


  • 0
    J
    class Solution {
        public int maxA(int N) {
            int[] result = new int[N];
            for(int i = 0; i < 3 && i <  N; i++)
                result[i] = i+1;
            
            int i = 4;
            while(i <= N){
                result[i-1] = i;
                int j = i;
                while(j > 3){
                    result[i-1] = Math.max(result[i-1], (i - j + 2) * result[j - 3 -1]);
                    j--;
                }
                i++;
            }
            
            return result[N-1];
        }
    }
    

Log in to reply
 

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