java.lang.Object
g0801_0900.s0889_construct_binary_tree_from_preorder_and_postorder_traversal.Solution

public class Solution extends Object
889 - Construct Binary Tree from Preorder and Postorder Traversal.<p>Medium</p> <p>Given two integer arrays, <code>preorder</code> and <code>postorder</code> where <code>preorder</code> is the preorder traversal of a binary tree of <strong>distinct</strong> values and <code>postorder</code> is the postorder traversal of the same tree, reconstruct and return <em>the binary tree</em>.</p> <p>If there exist multiple answers, you can <strong>return any</strong> of them.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/07/24/lc-prepost.jpg" alt="" /></p> <p><strong>Input:</strong> preorder = [1,2,4,5,3,6,7], postorder = [4,5,2,6,7,3,1]</p> <p><strong>Output:</strong> [1,2,3,4,5,6,7]</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> preorder = [1], postorder = [1]</p> <p><strong>Output:</strong> [1]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= preorder.length <= 30</code></li> <li><code>1 <= preorder[i] <= preorder.length</code></li> <li>All the values of <code>preorder</code> are <strong>unique</strong>.</li> <li><code>postorder.length == preorder.length</code></li> <li><code>1 <= postorder[i] <= postorder.length</code></li> <li>All the values of <code>postorder</code> are <strong>unique</strong>.</li> <li>It is guaranteed that <code>preorder</code> and <code>postorder</code> are the preorder traversal and postorder traversal of the same binary tree.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • constructFromPrePost

      public TreeNode constructFromPrePost(int[] preorder, int[] postorder)