Golang concise solution using queue
The trick to manage each level is store the queue length qlen before checking each node and appending its children to the queue. So we can iterate level by leve
The trick to manage each level is store the queue length `qlen` before checking each node and appending its children to the queue. So we can iterate level by level.\n\n```\nfunc levelOrder(root *TreeNode) [][]int {\n\tif root == nil {\n\t\treturn [][]int{}\n\t}\n\n\tvar res [][]int\n\tqueue := []*TreeNode{root}\n\tfor len(queue) > 0 {\n\t\tqlen := len(queue)\n\t\tvar level []int\n\t\tfor i := 0; i < qlen; i++ {\n\t\t\tnode := queue[0]\n\t\t\tlevel = append(level, node.Val)\n\t\t\tqueue = queue[1:]\n\n\t\t\tif node.Left != nil {\n\t\t\t\tqueue = append(queue, node.Left)\n\t\t\t}\n\t\t\tif node.Right != nil {\n\t\t\t\tqueue = append(queue, node.Right)\n\t\t\t}\n\t\t}\n\t\tres = append(res, level)\n\t}\n\treturn res\n}\n```
['Go']