// Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.

// For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13, return 2 because 13 = 4 + 9.


/**
 * @param {number} n
 * @return {number}
 */



var numSquares = function(n) {
    var possible = [0],
        len, temp;
    while( possible.length <= n ){
        len = possible.length;
        temp = n;
        for( var i=1; i*i<=len; i++ ){
            if( temp > possible[len-i*i]+1 ){
                temp = possible[len-i*i]+1;
            }
        }
        possible.push( temp );
    }
    return possible[n];
};

@@ -279,16 +279,47 @@
 r%7D%0A */%0A%0A
+%0A// Static Dynamic Programming:
 %0A%0Avar nu
@@ -508,16 +508,119 @@
 ; i++ )%7B
+ // %5B0%5D -%3E building up our array%0A            console.log(%22tmp: %22, temp, %22element: %22, possible%5Blen-i*i%5D)
 %0A       
@@ -657,16 +657,45 @@
 *i%5D+1 )%7B
+ // 9 %3E possible%5B 1 - 1*1 %5D+1
 %0A       
@@ -730,16 +730,59 @@
 -i*i%5D+1;
+// temp = possible%5B 1 - 1*1 %5D+1 -%3E temp = 1
 %0A       
@@ -828,16 +828,26 @@
  temp );
+ // %5B0, 1%5D
 %0A    %7D%0A 
@@ -872,8 +872,9 @@
 %5Bn%5D;%0A%7D;%0A
+%0A

add solution