
g0001_0100.s0096_unique_binary_search_trees.solution.rb Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-all Show documentation
Show all versions of leetcode-in-all Show documentation
104 LeetCode algorithm problem solutions
# #Medium #Top_100_Liked_Questions #Dynamic_Programming #Math #Tree #Binary_Tree
# #Binary_Search_Tree #Dynamic_Programming_I_Day_11 #Big_O_Time_O(n)_Space_O(1)
# #2023_11_22_Time_57_ms_(61.54%)_Space_211_MB_(76.92%)
# @param {Integer} n
# @return {Integer}
def num_trees(n)
result = 1
for i in 0...n
result *= (2 * n - i)
result /= (i + 1)
end
result /= (n + 1)
result.to_i
end
© 2015 - 2025 Weber Informatics LLC | Privacy Policy