Tap here to switch tabs
Problem
Submissions

Problem: Reverse Odd Levels of Binary Tree

Try to solve the Reverse Odd Levels of Binary Tree problem.

Statement

Given the root of a perfect binary tree, reverse the node values at each odd level of the tree.

The level of a node is defined as the number of edges on the path from the root to that node, where the root is at level 00.

Return the root of the reversed tree.

Constraints:

  • The number of nodes in the tree is in the range [1,214][1, 2^{14}].

  • 0≤0 \leq Node.val ≤105\leq 10^5

  • root is a perfect binary tree.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Reverse Odd Levels of Binary Tree

Try to solve the Reverse Odd Levels of Binary Tree problem.

Statement

Given the root of a perfect binary tree, reverse the node values at each odd level of the tree.

The level of a node is defined as the number of edges on the path from the root to that node, where the root is at level 00.

Return the root of the reversed tree.

Constraints:

  • The number of nodes in the tree is in the range [1,214][1, 2^{14}].

  • 0≤0 \leq Node.val ≤105\leq 10^5

  • root is a perfect binary tree.