This commit is contained in:
krahets
2023-09-29 21:43:04 +08:00
parent c10c457827
commit 543ecebfd0
4 changed files with 35 additions and 13 deletions

View File

@@ -91,10 +91,15 @@ comments: true
```javascript title=""
/* 二叉树节点类 */
function TreeNode(val, left, right) {
this.val = (val === undefined ? 0 : val); // 节点值
this.left = (left === undefined ? null : left); // 左子节点引用
this.right = (right === undefined ? null : right); // 右子节点引用
class TreeNode {
val; // 节点值
left; // 左子节点指针
right; // 右子节点指针
constructor(val, left, right) {
this.val = val === undefined ? 0 : val;
this.left = left === undefined ? null : left;
this.right = right === undefined ? null : right;
}
}
```