首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
不同的二叉搜索树
[编程题]不同的二叉搜索树
热度指数:14034
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32M,其他语言64M
算法知识视频讲解
给定一个值n,能构建出多少不同的值包含1...n的二叉搜索树(
BST
)?
例如
给定 n = 3, 有五种不同的二叉搜索树
(
BST
)
示例1
输入
3
输出
5
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(5)
邀请回答
收藏(150)
分享
提交结果有问题?
93个回答
7篇题解
开通博客
一叶浮尘
发表于 2020-04-11 12:34:42
给定一个值n,能构建出多少不同的值包含1...n的二叉搜索树(BST)?例如给定 n = 3, 有五种不同的二叉搜索树(BST) 这果然是一道easy的题目,因为纯靠数学推导,我们用f(n)表示对n的求解结果,在草稿上画画,你就知道f(1) = 1;f(2) = f(1)+f(1);f(3) =
展开全文
华科不平凡
发表于 2020-08-23 02:51:23
设值为n的情况下,可以组成f(n)个二叉搜索树,根据规律可知: f(0) = 1 f(1) = 1 f(n) += f(k-1)*f(n-k), 其中k=1,2,...n 显然,这是一个动态规划问题,实现如👇: // // Created by jt on 2020/8/23. // #inc
展开全文
jing_zhong
发表于 2021-09-05 08:17:47
题目描述:给定一个值n,能构建出多少不同的值包含1...n的二叉搜索树(BST)?例如:给定 n = 3, 有五种不同的二叉搜索树(BST)示例1: 输入:3
展开全文
我是嫩叠
发表于 2024-10-05 20:05:41
class Solution { public: /** * * @param n int整型 * @return int整型 */ int numTrees(int n) { vector<int> dp(n
展开全文
黑眼X
发表于 2025-10-10 17:39:24
import java.util.*; public class Solution { /** *使用 卡特兰数(Catalan)公式 * @param n int整型 * @return int整型 */ public in
展开全文
you_config
发表于 2025-03-04 01:10:27
# # # @param n int整型 # @return int整型 # class Solution: def numTrees(self , n ): # write code here def function(k): i
展开全文
O-Precedence
发表于 2021-09-09 14:46:38
动态规划 public class Solution { public int numTrees (int n) { int[] dp = new int[n+1]; dp[0] = 1; dp[1] = 1; for(int
展开全文
问题信息
树
难度:
93条回答
150收藏
21771浏览
热门推荐
通过挑战的用户
查看代码
追赶太阳的小辣...
2022-10-03 16:25:36
牛客51536...
2022-09-16 23:31:15
牛客15136...
2022-09-08 20:21:49
牛客84407...
2022-09-03 11:23:33
逃离_舒适圈
2022-08-30 21:48:05
相关试题
若主机甲与主机乙之间已建立一个TC...
网络基础
评论
(1)
来自
2024年秋招-蚂蚁集团...
在 Linux 中,有一个名为 t...
Linux
评论
(1)
在 Kafka 中要实现端到端的“...
Kafka
评论
(1)
为了实现跨多个 Topic-Par...
Kafka
评论
(1)
在 Go 语言中,切片(slice...
Go
评论
(1)
不同的二叉搜索树
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; public class Solution { /** * * @param n int整型 * @return int整型 */ public int numTrees (int n) { // write code here } }
class Solution { public: /** * * @param n int整型 * @return int整型 */ int numTrees(int n) { // write code here } };
# # # @param n int整型 # @return int整型 # class Solution: def numTrees(self , n ): # write code here
/** * * @param n int整型 * @return int整型 */ function numTrees( n ) { // write code here } module.exports = { numTrees : numTrees };
# # # @param n int整型 # @return int整型 # class Solution: def numTrees(self , n ): # write code here
package main /** * * @param n int整型 * @return int整型 */ func numTrees( n int ) int { // write code here }
3
5