[leetcode刷题系列]Unique Binary Search Trees

来源:互联网 发布:js验证11位手机号码 编辑:程序博客网 时间:2024/05/21 22:21

也许算是dp题目把- -

class Solution {    int ans[100];public:    int numTrees(int n) {        // Start typing your C/C++ solution below        // DO NOT write int main() function        ans[0] = 1;        for(int i = 1; i <= n; ++ i){            int sum = 0;            for(int j = 1; j <= i; ++ j)                sum += ans[j - 1] * ans[i - j];            ans[i] = sum;        }        return ans[n];    }};


原创粉丝点击