Skip to content

Instantly share code, notes, and snippets.

@xzhang311
Created August 19, 2016 16:10
class Solution {
public:
int numSquares(int n) {
vector<int> myT(n+1, INT_MAX);
myT[0]=0;
for(int i=1; i<=n; i++){
for(int j=1; j*j<=i; j++)
myT[i] = min(myT[i], myT[i-j*j]+1);
}
return myT.back();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment