AlgoFrames

Fix the post-order traversal

Standard · Find the bug · about 5 min

This function should return the values in post-order, but it returns pre-order. Click the line that is wrong.

Example 1

Input:

[[4,2,6,1,3]]

Output:

[1,3,2,6,4]

The buggy code returns 4 2 1 3 6.

Constraints

  • 0 ≤ number of nodes ≤ 1,000
  • -1,000 ≤ Node.val ≤ 1,000
  • The tree is given in level order; null marks a missing child

Learn the idea first: Pre-order, in-order, post-order, a visual lesson.

More Pre-order, in-order, post-order problems