Unique Binary Search Trees

Posted RenewDo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unique Binary Search Trees相关的知识,希望对你有一定的参考价值。

1、Unique Binary Search Trees

 1 class Solution {
 2 public:
 3     int numTrees(int n) {
 4         if(n < 1)
 5              return 1;
 6         vector<int> res(n+1, 0);
 7         res[0] = 1;
 8         res[1] = 1;
 9         for(int i=2; i<=n; i++)
10         {
11             for(int j=0; j<i; j++)
12             {
13                 res[i] += res[j]*res[i-1-j];
14             }
15         }
16         return res[n];
17     }
18 };

 

以上是关于Unique Binary Search Trees的主要内容,如果未能解决你的问题,请参考以下文章

Unique Binary Search Trees

Unique Binary Search Trees

树Unique Binary Search Trees II

树Unique Binary Search Trees

96_Unique Binary Search Trees

96. Unique Binary Search Trees