LeetCode 096 Unique Binary Search Trees

LeetCode 096 Unique Binary Search Trees Problem

Download Code
class Solution(object):
    def numTrees(self, n):
        :type n: int
        :rtype: int
        # https://leetcode.com/discuss/86650/fantastic-clean-java-dp-solution-with-detail-explaination
        dp = [0] * (n + 1)
        dp[0] = 1
        dp[1] = 1
        for level in range(2, n + 1):
            for root in range(1, level + 1):
                dp[level] += dp[level - root] * dp[root - 1]
        return dp[n]
Download Unique Binary Search Trees.py

List of all Unique Binary Search Trees problems

Leetcode 096 Unique Binary Search Trees problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.

Feedback is the most important part of any website.

If you have any query, suggestion or feedback, Please feel free to contact us.