From 374190e2232ec9daeffe20660d1020199a17c10b Mon Sep 17 00:00:00 2001 From: ZongqinWang <1722249371@qq.com> Date: Sat, 18 Jun 2022 22:25:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200096.=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E7=9A=84=E4=BA=8C=E5=8F=89=E6=90=9C=E7=B4=A2=E6=A0=91.md=20Sca?= =?UTF-8?q?la=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0096.不同的二叉搜索树.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/problems/0096.不同的二叉搜索树.md b/problems/0096.不同的二叉搜索树.md index 25561b50..a33421ae 100644 --- a/problems/0096.不同的二叉搜索树.md +++ b/problems/0096.不同的二叉搜索树.md @@ -227,7 +227,7 @@ const numTrees =(n) => { }; ``` -TypeScript +### TypeScript ```typescript function numTrees(n: number): number { @@ -282,5 +282,22 @@ int numTrees(int n){ } ``` +### Scala + +```scala +object Solution { + def numTrees(n: Int): Int = { + var dp = new Array[Int](n + 1) + dp(0) = 1 + for (i <- 1 to n) { + for (j <- 1 to i) { + dp(i) += dp(j - 1) * dp(i - j) + } + } + dp(n) + } +} +``` + -----------------------