Skip to content

Commit

Permalink
Time: 2 ms (8.93%), Space: 5.5 MB (83.53%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
hovanhoa committed Jan 13, 2025
1 parent c187d88 commit 632d61b
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func levelOrder(root *TreeNode) [][]int {
return [][]int{}
}


ans := [][]int{}
queue := []*TreeNode{root}

Expand All @@ -22,16 +23,13 @@ func levelOrder(root *TreeNode) [][]int {
node := queue[0]
queue = queue[1:]

if node != nil {
level = append(level, node.Val)

if node.Left != nil {
queue = append(queue, node.Left)
}
level = append(level, node.Val)
if node.Left != nil {
queue = append(queue, node.Left)
}

if node.Right != nil {
queue = append(queue, node.Right)
}
if node.Right != nil {
queue = append(queue, node.Right)
}
}

Expand Down

0 comments on commit 632d61b

Please sign in to comment.