Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ca18b7d

Browse files
committed
添加 0538.把二叉搜索树转换为累加树.md Scala版本
1 parent 474ae02 commit ca18b7d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎problems/0538.把二叉搜索树转换为累加树.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,24 @@ function convertBST(root: TreeNode | null): TreeNode | null {
352352
};
353353
```
354354

355+
## Scala
356+
357+
```scala
358+
object Solution {
359+
def convertBST(root: TreeNode): TreeNode = {
360+
var sum = 0
361+
def convert(node: TreeNode): Unit = {
362+
if (node == null) return
363+
convert(node.right)
364+
sum += node.value
365+
node.value = sum
366+
convert(node.left)
367+
}
368+
convert(root)
369+
root
370+
}
371+
}
372+
```
355373

356374

357375
-----------------------

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /