public int numTrees(int n) {
    	int cnt[] = new int[n + 1];
    	cnt[1] = 1;
    	for (int i = 2; i <= n; i++)
    	{
    		for (int j = 1; j <= i; j++)
    			if (j == 1 || j == i)
    				cnt[i] += cnt[i-1];
    			else
    				cnt[i] += cnt[j - 1] * cnt[i - j]; 
    	}
    	return cnt[n];
    }