For N<4 Only One Is Perfect Square !
class Solution {//Memoization!
public int numSquares(int n) {
int storage[] = new int[n+1];
Arrays.fill(storage,Integer.MAX_VALUE);
return minInteger(n,storage);
}
private int minInteger(int n , int[] storage){
if(n==0 || n==1 || n==2 || n==3)
return n;
if(storage[n]!=Integer.MAX_VALUE)
return storage[n];
for(int i=1;i*i<=n;i++){
storage[n]=Math.min(storage[n],1+minInteger(n-i*i,storage));
}
return storage[n];
}
}//80 msUpVote If U Like!