feat: add ruby code blocks - chapter tree (#1293)

This commit is contained in:
khoaxuantu
2024-04-19 22:42:20 +07:00
committed by GitHub
parent 587344da62
commit 74f1a63e8c
3 changed files with 46 additions and 7 deletions

View File

@@ -129,9 +129,9 @@ AVL 树既是二叉搜索树,也是平衡二叉树,同时满足这两类二
right: TreeNode | null; // 右子节点指针
constructor(val?: number, height?: number, left?: TreeNode | null, right?: TreeNode | null) {
this.val = val === undefined ? 0 : val;
this.height = height === undefined ? 0 : height;
this.left = left === undefined ? null : left;
this.right = right === undefined ? null : right;
this.height = height === undefined ? 0 : height;
this.left = left === undefined ? null : left;
this.right = right === undefined ? null : right;
}
}
```
@@ -214,7 +214,18 @@ AVL 树既是二叉搜索树,也是平衡二叉树,同时满足这两类二
=== "Ruby"
```ruby title=""
### AVL 树节点类 ###
class TreeNode
attr_accessor :val # 节点值
attr_accessor :height # 节点高度
attr_accessor :left # 左子节点引用
attr_accessor :right # 右子节点引用
def initialize(val)
@val = val
@height = 0
end
end
```
=== "Zig"