mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
修改二叉树系列19 从中序与后序遍历序列构造二叉树JS版本变量名 preorder->inorder
This commit is contained in:
@ -790,7 +790,7 @@ func findRootIndex(target int,inorder []int) int{
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var buildTree = function(inorder, postorder) {
|
var buildTree = function(inorder, postorder) {
|
||||||
if (!preorder.length) return null;
|
if (!inorder.length) return null;
|
||||||
const rootVal = postorder.pop(); // 从后序遍历的数组中获取中间节点的值, 即数组最后一个值
|
const rootVal = postorder.pop(); // 从后序遍历的数组中获取中间节点的值, 即数组最后一个值
|
||||||
let rootIndex = inorder.indexOf(rootVal); // 获取中间节点在中序遍历中的下标
|
let rootIndex = inorder.indexOf(rootVal); // 获取中间节点在中序遍历中的下标
|
||||||
const root = new TreeNode(rootVal); // 创建中间节点
|
const root = new TreeNode(rootVal); // 创建中间节点
|
||||||
|
Reference in New Issue
Block a user