首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
有多少个不同的二叉搜索树
[编程题]有多少个不同的二叉搜索树
热度指数:835
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
算法知识视频讲解
给定一个由节点值从 1 到 n 的 n 个节点。请问由多少种不同的方法用这 n 个节点构成互不相同的二叉搜索树。
例如:当n=2时有
数据范围:
示例1
输入
2
输出
2
示例2
输入
3
输出
5
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(0)
邀请回答
收藏(17)
分享
纠错
提交结果有问题?
5个回答
5篇题解
开通博客
17c89
发表于 2024-07-22 15:53:01
import java.math.BigInteger; import java.util.*; /** * NC310 不同的二叉搜索树(一) * @author d3y1 */ public class Solution { /** * 代码中的类名、方法名、参数名已经
展开全文
奶ve
发表于 2024-05-11 17:34:38
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ in
展开全文
烧骨花生粥
发表于 2024-04-21 23:47:16
偷个懒,dp以后再说。 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param n int整型 # @return int整型 # class Solution: def BSTCount(self , n: int) -> in
展开全文
小步惊惊
发表于 2022-04-29 15:00:42
看力扣题题解
kun1224
发表于 2023-11-16 10:36:51
代码看着行数很少,其实思路不好想dp数组含义:下表i表示i个不同元素,dp[i]表示二叉搜索的数目递推公式:dp[i] = dp[0]*dp[i-1] + dp[1] * dp[i-2] ......dp[i-2] * dp[1] + dp[i-1]*dp[0]dp数组初始化:dp[0] =1 ,d
展开全文
问题信息
动态规划
组合数学
难度:
5条回答
17收藏
3170浏览
热门推荐
通过挑战的用户
查看代码
牛客11870...
2022-09-15 10:38:58
Hadwinling
2022-09-13 15:25:52
牛客74836...
2022-09-09 19:52:24
林子20190...
2022-09-07 17:50:31
德玛尔爱打球
2022-09-06 18:49:09
相关试题
从所给的四个选项中,选择最合适的一...
图形推理
评论
(1)
在大语言模型中,什么是"Gated...
大模型开发
评论
(1)
心理暗示是指个体在无意识情况下,从...
定义判断
评论
(1)
关于大模型“上下文窗口”的理解,以...
大模型概念
评论
(1)
Vue Router的全局前置守卫...
Vue
评论
(1)
有多少个不同的二叉搜索树
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ public int BSTCount (int n) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ int BSTCount(int n) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param n int整型 # @return int整型 # class Solution: def BSTCount(self , n ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ public int BSTCount (int n) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ function BSTCount( n ) { // write code here } module.exports = { BSTCount : BSTCount };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param n int整型 # @return int整型 # class Solution: def BSTCount(self , n: int) -> int: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ func BSTCount( n int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ int BSTCount(int n ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param n int整型 # @return int整型 # class Solution def BSTCount(n) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ def BSTCount(n: Int): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ fun BSTCount(n: Int): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ public int BSTCount (int n) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ export function BSTCount(n: number): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ func BSTCount ( _ n: Int) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ pub fn BSTCount(&self, n: i32) -> i32 { // write code here } }
2
2
3
5