|
| 1 | +<p>Given the <code>root</code> of a binary tree, return <em>the postorder traversal of its nodes' values</em>.</p> |
| 2 | + |
| 3 | +<p> </p> |
| 4 | +<p><strong class="example">Example 1:</strong></p> |
| 5 | + |
| 6 | +<div class="example-block"> |
| 7 | +<p><strong>Input:</strong> <span class="example-io">root = [1,null,2,3]</span></p> |
| 8 | + |
| 9 | +<p><strong>Output:</strong> <span class="example-io">[3,2,1]</span></p> |
| 10 | + |
| 11 | +<p><strong>Explanation:</strong></p> |
| 12 | + |
| 13 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2024/08/29/screenshot-2024-08-29-202743.png" style="width: 200px; height: 264px;" /></p> |
| 14 | +</div> |
| 15 | + |
| 16 | +<p><strong class="example">Example 2:</strong></p> |
| 17 | + |
| 18 | +<div class="example-block"> |
| 19 | +<p><strong>Input:</strong> <span class="example-io">root = [1,2,3,4,5,null,8,null,null,6,7,9]</span></p> |
| 20 | + |
| 21 | +<p><strong>Output:</strong> <span class="example-io">[4,6,7,5,2,9,8,3,1]</span></p> |
| 22 | + |
| 23 | +<p><strong>Explanation:</strong></p> |
| 24 | + |
| 25 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2024/08/29/tree_2.png" style="width: 350px; height: 286px;" /></p> |
| 26 | +</div> |
| 27 | + |
| 28 | +<p><strong class="example">Example 3:</strong></p> |
| 29 | + |
| 30 | +<div class="example-block"> |
| 31 | +<p><strong>Input:</strong> <span class="example-io">root = []</span></p> |
| 32 | + |
| 33 | +<p><strong>Output:</strong> <span class="example-io">[]</span></p> |
| 34 | +</div> |
| 35 | + |
| 36 | +<p><strong class="example">Example 4:</strong></p> |
| 37 | + |
| 38 | +<div class="example-block"> |
| 39 | +<p><strong>Input:</strong> <span class="example-io">root = [1]</span></p> |
| 40 | + |
| 41 | +<p><strong>Output:</strong> <span class="example-io">[1]</span></p> |
| 42 | +</div> |
| 43 | + |
| 44 | +<p> </p> |
| 45 | +<p><strong>Constraints:</strong></p> |
| 46 | + |
| 47 | +<ul> |
| 48 | + <li>The number of the nodes in the tree is in the range <code>[0, 100]</code>.</li> |
| 49 | + <li><code>-100 <= Node.val <= 100</code></li> |
| 50 | +</ul> |
| 51 | + |
| 52 | +<p> </p> |
| 53 | +<strong>Follow up:</strong> Recursive solution is trivial, could you do it iteratively? |
0 commit comments