Участник:Novitskiy97/Unique Binary Search Trees

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/unique-binary-search-trees/

Python 3

class Solution:
    def numTrees(self, n: int) -> int:
        catalan = [1]
        for k in range(1, n + 1):
            catalan.append(0)
            for i in range(k):
                catalan[k] += catalan[i] * catalan[k-1-i]
        return catalan[n]