/
githubmirror
/
hello-algo
Обзор
Документация
Войти
/
githubmirror
/
hello-algo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
en/codes/javascript/modules/TreeNode.js
35 строк
884 B
Yudong Jin
Translate all code to English (#1836)
31 дек 2025, 02:44
Не верифицирован
31 дек 2025, 02:44
2778a6f
Код
Авторство
О чём код?
/** * File: TreeNode.js * Created Time: 2022-12-04 * Author: IsChristina (christinaxia77@foxmail.com) */ /* Binary tree node */ class TreeNode { val; // Node value left; // Left child pointer right; // Right child pointer height; // Node height constructor(val, left, right, height) { this.val = val === undefined ? 0 : val; this.left = left === undefined ? null : left; this.right = right === undefined ? null : right; this.height = height === undefined ? 0 : height; } } /* Deserialize array to binary tree */ function arrToTree(arr, i = 0) { if (i < 0 || i >= arr.length || arr[i] === null) { return null; } let root = new TreeNode(arr[i]); root.left = arrToTree(arr, 2 * i + 1); root.right = arrToTree(arr, 2 * i + 2); return root; } module.exports = { TreeNode, arrToTree, };