Skip to content

Commit 653f508

Browse files
committed
Runtime: 92 ms (Top 87.91%) | Memory: 45.1 MB (Top 70.11%)
1 parent f97bec8 commit 653f508

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
// Runtime: 92 ms (Top 87.91%) | Memory: 45.1 MB (Top 70.11%)
12
/**
23
* Definition for a binary tree node.
34
* function TreeNode(val, left, right) {
4-
* this.val = (val===undefined ? 0 : val)
5-
* this.left = (left===undefined ? null : left)
6-
* this.right = (right===undefined ? null : right)
5+
* this.val = (val===undefined ? 0 : val)
6+
* this.left = (left===undefined ? null : left)
7+
* this.right = (right===undefined ? null : right)
78
* }
89
*/
910
/**
@@ -13,19 +14,19 @@
1314
*/
1415
var buildTree = function(inorder, postorder) {
1516
let postIndex = postorder.length - 1
16-
17+
1718
const dfs = (left, right) => {
1819
if (left > right) return null
19-
20+
2021
const val = postorder[postIndex--]
2122
const mid = inorder.findIndex(e => e === val)
2223
const root = new TreeNode(val)
2324

2425
root.right = dfs(mid + 1, right)
2526
root.left = dfs(left, mid - 1)
26-
27+
2728
return root
2829
}
29-
30+
3031
return dfs(0, inorder.length - 1)
31-
};
32+
};

0 commit comments

Comments
 (0)