Binary Tree Zigzag Level Order Traversal

Medium Topics Company Tags

You are given the root of a binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the next level and alternate between).

Example 1:

Input: root = [1,2,3,4,5,6,7]

Output: [[1],[3,2],[4,5,6,7]]

Example 2:

Input: root = [1]

Output: [[1]]

Constraints:

  • 0 <= number of nodes in the tree <= 2000
  • -100 <= Node.val <= 100


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.


Solution 1
||Ln 1, Col 1

root =