mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-15 04:38:30 +08:00
build
This commit is contained in:
@ -183,6 +183,16 @@ comments: true
|
||||
=== "Kotlin"
|
||||
|
||||
```kotlin title=""
|
||||
/* 二叉树节点类 */
|
||||
class TreeNode(val _val: Int) { // 节点值
|
||||
val left: TreeNode? = null // 左子节点引用
|
||||
val right: TreeNode? = null // 右子节点引用
|
||||
}
|
||||
```
|
||||
|
||||
=== "Ruby"
|
||||
|
||||
```ruby title=""
|
||||
|
||||
```
|
||||
|
||||
@ -414,6 +424,22 @@ comments: true
|
||||
=== "Kotlin"
|
||||
|
||||
```kotlin title="binary_tree.kt"
|
||||
// 初始化节点
|
||||
val n1 = TreeNode(1)
|
||||
val n2 = TreeNode(2)
|
||||
val n3 = TreeNode(3)
|
||||
val n4 = TreeNode(4)
|
||||
val n5 = TreeNode(5)
|
||||
// 构建节点之间的引用(指针)
|
||||
n1.left = n2
|
||||
n1.right = n3
|
||||
n2.left = n4
|
||||
n2.right = n5
|
||||
```
|
||||
|
||||
=== "Ruby"
|
||||
|
||||
```ruby title="binary_tree.rb"
|
||||
|
||||
```
|
||||
|
||||
@ -568,6 +594,17 @@ comments: true
|
||||
=== "Kotlin"
|
||||
|
||||
```kotlin title="binary_tree.kt"
|
||||
val P = TreeNode(0)
|
||||
// 在 n1 -> n2 中间插入节点 P
|
||||
n1.left = P
|
||||
P.left = n2
|
||||
// 删除节点 P
|
||||
n1.left = n2
|
||||
```
|
||||
|
||||
=== "Ruby"
|
||||
|
||||
```ruby title="binary_tree.rb"
|
||||
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user