mirror of
https://github.com/xlucn/PAT.git
synced 2026-11-05 06:37:35 +08:00
15 lines
1.4 KiB
HTML
15 lines
1.4 KiB
HTML
Postorder Traversal
|
|
<div class="ques-view"><p>Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and inorder traversal sequences, you are supposed to output the first number of the postorder traversal sequence of the corresponding binary tree.</p>
|
|
<h3 id="input-specification-">Input Specification:</h3>
|
|
<p>Each input file contains one test case. For each case, the first line gives a positive integer N (<span class="katex"><span class="katex-mathml"><math><mrow><mo>≤</mo></mrow>\le</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.63597em;"></span><span class="strut bottom" style="height:0.7719400000000001em;vertical-align:-0.13597em;"></span><span class="base textstyle uncramped"><span class="mrel">≤</span></span></span></span> 50,000), the total number of nodes in the binary tree. The second line gives the preorder sequence and the third line gives the inorder sequence. All the numbers in a line are separated by a space.</p>
|
|
<h3 id="output-specification-">Output Specification:</h3>
|
|
<p>For each test case, print in one line the first number of the postorder traversal sequence of the corresponding binary tree.</p>
|
|
<h3 id="sample-input-">Sample Input:</h3>
|
|
<pre><code class="lang-in">7
|
|
1 2 3 4 5 6 7
|
|
2 3 1 5 4 7 6
|
|
</code></pre>
|
|
<h3 id="sample-output-">Sample Output:</h3>
|
|
<pre><code class="lang-out">3
|
|
</code></pre>
|
|
</div> |