Skip to content

Instantly share code, notes, and snippets.

@monotykamary
Created April 7, 2026 08:07
Show Gist options
  • Select an option

  • Save monotykamary/6743af4e9e79d81a3755b5b4f05b0b4d to your computer and use it in GitHub Desktop.

Select an option

Save monotykamary/6743af4e9e79d81a3755b5b4f05b0b4d to your computer and use it in GitHub Desktop.
Golang binary tree traversal

Given the root of a binary tree, return the level order traversal of its nodes' values (i.e., from left to right, level by level). [1, 2]

Example 1:

  • Input: root = [3,9,20,null,null,15,7]
  • Output: [[3],[9,20],[15,7]] [1, 3, 4, 5, 6]

Example 2:

  • Input: root = [1]
  • Output: [[1]] [1, 7]

Example 3:

  • Input: root = []
  • Output: [] [1]

Constraints:

  • The number of nodes in the tree is in the range [0, 2000].
  • -1000 <= Node.val <= 1000. [1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment