Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by registered user nikhil2802 ( 4 years ago )
class Solution
{
    public int MinSquares(int n)
    {
        // Code here
        int[] dp = new int[n + 1];
        dp[0] = 0;
        dp[1] = 1;
        for(int i = 2; i <= n; i++)
        {
            int min = Integer.MAX_VALUE;
            for(int j = 1; j * j <= i; j++)
            {
                int rem = i - j * j;
                if(dp[rem] < min)
                {
                    min = dp[rem];
                }
            }
            dp[i] = min + 1;
        }
        return dp[n];
    }
}

 

Revise this Paste

Your Name: Code Language: