题目 Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. Show Tags Show Similar Problems 分析 跟上一道题同样的道理. AC代码 class Solution { public: template <typename Iter> TreeN…
题目 Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 分析 给定一颗二叉树的前序和中序遍历序列,求该二叉树. 我们手动做过很多这样的题目,掌握了其规则~ 前序遍历第一个元素为树的root节点,然后在中序序列中查找该值,元素左侧为左子树,右侧为右子树: 求出左子树个数cou…
题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. 思路: 题目的大意是[判断一个二叉树是不是平衡二叉树 首先了解…
题目 Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. 分析 判断给定二叉树是否为二叉平衡树,即任一节点的左右子树高度差…
Flatten Binary Tree to Linked List: Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6 这题的主要难点是"in-place".因为这个flatten的顺序是中.左.右(相当于中序遍历),所…