题目描述

方法思路
class Solution {
//Runtime: 9 ms, faster than 75.00%
//Memory Usage: 39.7 MB, less than 91.45%
public TreeNode constructFromPrePost(int[] pre, int[] post) {
int N = pre.length;
if (N == 0) return null;
TreeNode root = new TreeNode(pre[0]);
if (N == 1) return root;
int L = 0;
for (int i = 0; i < N; ++i)
if (post[i] == pre[1])
L = i+1;
root.left = constructFromPrePost(Arrays.copyOfRange(pre, 1, L+1), Arrays.copyOfRange(post, 0, L));
root.right = constructFromPrePost(Arrays.copyOfRange(pre, L+1, N), Arrays.copyOfRange(post, L, N-1));
return root;
}
}

博客包含题目描述和方法思路两部分内容,虽未给出具体信息,但围绕这两方面展开,为解决问题提供了基本框架。
253

被折叠的 条评论
为什么被折叠?



