标签:ota ati binary com bin str bsp exp title
Example: Input: 3 Output: 5 Explanation: Given n = 3, there are a total of 5 unique BST‘s: 1 3 3 2 1 \ / / / \ 3 2 1 1 3 2 / / \ 2 1 2 3
code
recursion
class Solution { public: int numTrees(int n) { if(n<=1) return 1; int sum=0; for(int i=1;i<=n;++i)//每个结点做一次根 sum+=numTrees(i-1)*numTrees(n-i); return sum; } };
dp
标签:ota ati binary com bin str bsp exp title
原文地址:https://www.cnblogs.com/tianzeng/p/10952125.html