Skip to content

Instantly share code, notes, and snippets.

@fjc-oai
Created November 28, 2014 00:46
Show Gist options
  • Save fjc-oai/5f03366c1e4ac9ac13ed to your computer and use it in GitHub Desktop.
Save fjc-oai/5f03366c1e4ac9ac13ed to your computer and use it in GitHub Desktop.
class Solution {
public:
int numTrees(int n) {
vector<int>f(n+1,0);
f[0]=1;
for(int i=1;i<=n;i++){
for(int j=0;j<=i-1;j++)
f[i]+=f[j]*f[i-1-j];
}
return f[n];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment